Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-X Media library bug fix #176

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/css/styles.min.css

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions hdbt_admin.theme
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\media\MediaInterface;

/**
* Implements hook_preprocess().
Expand Down Expand Up @@ -375,3 +376,26 @@ function hdbt_admin_manipulate_custom_fields(array &$form) {
$form['hide_sidebar_navigation']['#type'] = 'hidden';
}
}

/**
* Implements hook_preprocess_HOOK().
*/
function hdbt_admin_preprocess_media(&$variables) {
if (
isset($variables['media']) &&
$variables['media'] instanceof MediaInterface &&
$variables['media']->bundle() === 'image'
) {
$current_language = $variables['current_langcode'];
$route = \Drupal::routeMatch();
if (!empty($route->getParameter('target'))) {
$current_language = $route->getParameter('target')->getId();
}

if ($variables['media']->hasTranslation($current_language)) {
$alt = $variables['media']
->getTranslation($current_language)->field_media_image->alt;
$variables['alt_text'] = $alt !== '""' ? $alt : FALSE;
}
}
}
1 change: 1 addition & 0 deletions src/scss/06_components/entity/__index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import 'media';
@import 'hel-map';
@import 'helfi-chart';
12 changes: 12 additions & 0 deletions src/scss/06_components/entity/_media.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.media-library-item__name,
.media-library-item__alt {
font-size: 0.875rem;
}

.media-library-item__alt {
font-weight: 500;

span {
font-weight: 400;
}
}
13 changes: 12 additions & 1 deletion src/scss/06_components/views/_media-library.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
.media-library-item__click-to-select-checkbox .form-boolean {
box-shadow: 0 3px 6px $color-black-50;
}
.pager {
width: 100%;
}
}

// Override edit-button position for media library widget.
// Override edit-button position for media library widget.
[dir="ltr"] .media-library-view--widget .media-library-item {
.media-library-item__edit {
right: 0.5rem;
}
}

[dir="rtl"] .media-library-view--widget .media-library-item {
.media-library-item__edit {
left: 0.5rem;
}
}
64 changes: 64 additions & 0 deletions templates/entity/media--media-library.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{#
/**
* @file
* Theme override of a media item in the media library.
*
* This is used for media that the user can select from the grid of media
* items. It is not used for items that have already been selected in the
* corresponding field widget, or for items that have been previously selected
* before adding new media to the library.
*
* Available variables:
* - media: The entity with limited access to object properties and methods.
* Only method names starting with "get", "has", or "is" and a few common
* methods such as "id", "label", and "bundle" are available. For example:
* - entity.getEntityTypeId() will return the entity type ID.
* - entity.hasField('field_example') returns TRUE if the entity includes
* field_example. (This does not indicate the presence of a value in this
* field.)
* Calling other methods, such as entity.delete(), will result in an exception.
* See \Drupal\Core\Entity\EntityInterface for a full list of methods.
* - name: Name of the media.
* - content: Media content.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
* - view_mode: View mode; for example, "teaser" or "full".
* - attributes: HTML attributes for the containing element.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - url: Direct URL of the media.
* - preview_attributes: HTML attributes for the preview wrapper.
* - metadata_attributes: HTML attributes for the expandable metadata area.
* - status: Whether or not the Media is published.
*
* @see template_preprocess_media()
*
* @ingroup themeable
*/
#}

<article{{ attributes.addClass('media-library-item__preview-wrapper') }}>
{% if content %}
<div{{ preview_attributes.addClass('media-library-item__preview js-media-library-item-preview') }}>
{{ content|without('name') }}
</div>
{% if not status %}
<div class="media-library-item__status">{{ "unpublished" | t }}</div>
{% endif %}
<div{{ metadata_attributes.addClass('media-library-item__attributes') }}>
<div class="media-library-item__name">{{ name }}</div>

<div class="media-library-item__alt">
{% if alt_text %}
{{ 'Alt'|t({}, {'context': 'Alt text in media library'}) }}:
<span>{{ alt_text }}</span>
{% else %}
{{ 'Alt'|t({}, {'context': 'Alt text in media library'}) }}:
<span>"" ({{ 'Empty'|t({}, {'context': 'Empty alt text in media library'}) }})</span>
{% endif %}
</div>
</div>
{% endif %}
</article>
4 changes: 4 additions & 0 deletions translations/fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ msgctxt "Accent color"
msgid "Accent"
msgstr "Korosteväri"

msgctxt "Empty alt text in media library"
msgid "Empty"
msgstr "Tyhjä"

msgid "Basic motif"
msgstr "Perus"

Expand Down
4 changes: 4 additions & 0 deletions translations/sv.po
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
msgid ""
msgstr ""

msgctxt "Empty alt text in media library"
msgid "Empty"
msgstr "Tom"

msgid "Published on"
msgstr "Publicerad på"