diff --git a/config/default/core.entity_form_display.media.h_svg.default.yml b/config/default/core.entity_form_display.media.h_svg.default.yml new file mode 100644 index 00000000..58cf2a2b --- /dev/null +++ b/config/default/core.entity_form_display.media.h_svg.default.yml @@ -0,0 +1,67 @@ +uuid: f7b62d00-aaf8-4969-982c-97eb9d273152 +langcode: en +status: true +dependencies: + config: + - field.field.media.h_svg.field_media_file + - media.type.h_svg + module: + - file + - path +id: media.h_svg.default +targetEntityType: media +bundle: h_svg +mode: default +content: + created: + type: datetime_timestamp + weight: 10 + region: content + settings: { } + third_party_settings: { } + field_media_file: + weight: 0 + settings: + progress_indicator: throbber + third_party_settings: { } + type: file_generic + region: content + langcode: + type: language_select + weight: 2 + region: content + settings: + include_locked: true + third_party_settings: { } + name: + type: string_textfield + weight: -5 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + path: + type: path + weight: 30 + region: content + settings: { } + third_party_settings: { } + status: + type: boolean_checkbox + settings: + display_label: true + weight: 100 + region: content + third_party_settings: { } + uid: + type: entity_reference_autocomplete + weight: 5 + settings: + match_operator: CONTAINS + size: 60 + placeholder: '' + match_limit: 10 + region: content + third_party_settings: { } +hidden: { } diff --git a/config/default/core.entity_form_display.media.h_svg.media_library.yml b/config/default/core.entity_form_display.media.h_svg.media_library.yml new file mode 100644 index 00000000..8f0d046a --- /dev/null +++ b/config/default/core.entity_form_display.media.h_svg.media_library.yml @@ -0,0 +1,36 @@ +uuid: a75bbef6-ba1e-4f54-a4ca-566421b8b8cd +langcode: en +status: true +dependencies: + config: + - core.entity_form_mode.media.media_library + - field.field.media.h_svg.field_media_file + - media.type.h_svg + module: + - file +id: media.h_svg.media_library +targetEntityType: media +bundle: h_svg +mode: media_library +content: + field_media_file: + type: file_generic + weight: 1 + region: content + settings: + progress_indicator: throbber + third_party_settings: { } + name: + type: string_textfield + settings: + size: 60 + placeholder: '' + weight: 0 + third_party_settings: { } + region: content +hidden: + created: true + langcode: true + path: true + status: true + uid: true diff --git a/config/default/core.entity_form_display.taxonomy_term.h_notification_type.default.yml b/config/default/core.entity_form_display.taxonomy_term.h_notification_type.default.yml index 071aa98d..9767bad0 100644 --- a/config/default/core.entity_form_display.taxonomy_term.h_notification_type.default.yml +++ b/config/default/core.entity_form_display.taxonomy_term.h_notification_type.default.yml @@ -3,9 +3,12 @@ langcode: en status: true dependencies: config: + - entity_browser.browser.h_svg_browser - field.field.taxonomy_term.h_notification_type.field_h_colour + - field.field.taxonomy_term.h_notification_type.field_h_icon - taxonomy.vocabulary.h_notification_type module: + - entity_browser - path - text id: taxonomy_term.h_notification_type.default @@ -15,7 +18,7 @@ mode: default content: description: type: text_textarea - weight: 2 + weight: 3 region: content settings: placeholder: '' @@ -27,9 +30,24 @@ content: third_party_settings: { } type: options_select region: content + field_h_icon: + type: entity_browser_entity_reference + weight: 2 + settings: + entity_browser: h_svg_browser + field_widget_display: rendered_entity + field_widget_display_settings: + view_mode: default + field_widget_edit: true + field_widget_remove: true + selection_mode: selection_append + field_widget_replace: false + open: false + third_party_settings: { } + region: content langcode: type: language_select - weight: 3 + weight: 4 region: content settings: include_locked: true @@ -44,7 +62,7 @@ content: third_party_settings: { } path: type: path - weight: 4 + weight: 5 region: content settings: { } third_party_settings: { } @@ -52,7 +70,7 @@ content: type: boolean_checkbox settings: display_label: true - weight: 5 + weight: 6 region: content third_party_settings: { } hidden: { } diff --git a/config/default/core.entity_view_display.media.h_svg.default.yml b/config/default/core.entity_view_display.media.h_svg.default.yml new file mode 100644 index 00000000..4ef3359a --- /dev/null +++ b/config/default/core.entity_view_display.media.h_svg.default.yml @@ -0,0 +1,38 @@ +uuid: 2c4dc9a4-2853-4659-8583-017f466586e0 +langcode: en +status: true +dependencies: + config: + - field.field.media.h_svg.field_media_file + - media.type.h_svg + module: + - file + - image +id: media.h_svg.default +targetEntityType: media +bundle: h_svg +mode: default +content: + field_media_file: + label: visually_hidden + weight: 0 + settings: + use_description_as_link_text: true + third_party_settings: { } + type: file_default + region: content + thumbnail: + type: image + weight: 1 + region: content + label: hidden + settings: + image_style: '' + image_link: '' + third_party_settings: { } +hidden: + created: true + langcode: true + name: true + search_api_excerpt: true + uid: true diff --git a/config/default/core.entity_view_display.media.h_svg.media_library.yml b/config/default/core.entity_view_display.media.h_svg.media_library.yml new file mode 100644 index 00000000..625b53d5 --- /dev/null +++ b/config/default/core.entity_view_display.media.h_svg.media_library.yml @@ -0,0 +1,32 @@ +uuid: a6873d3e-0c7d-4645-a863-b7aa72aabf99 +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.media.media_library + - field.field.media.h_svg.field_media_file + - image.style.medium + - media.type.h_svg + module: + - image +id: media.h_svg.media_library +targetEntityType: media +bundle: h_svg +mode: media_library +content: + thumbnail: + type: image + label: hidden + settings: + image_style: medium + image_link: '' + weight: 0 + third_party_settings: { } + region: content +hidden: + created: true + field_media_file: true + langcode: true + name: true + search_api_excerpt: true + uid: true diff --git a/config/default/core.entity_view_display.taxonomy_term.h_notification_type.default.yml b/config/default/core.entity_view_display.taxonomy_term.h_notification_type.default.yml index 4d49798e..dc126921 100644 --- a/config/default/core.entity_view_display.taxonomy_term.h_notification_type.default.yml +++ b/config/default/core.entity_view_display.taxonomy_term.h_notification_type.default.yml @@ -4,6 +4,7 @@ status: true dependencies: config: - field.field.taxonomy_term.h_notification_type.field_h_colour + - field.field.taxonomy_term.h_notification_type.field_h_icon - taxonomy.vocabulary.h_notification_type module: - panelizer @@ -27,6 +28,15 @@ content: third_party_settings: { } type: entity_reference_entity_view region: content + field_h_icon: + type: entity_reference_entity_view + weight: 1 + label: above + settings: + view_mode: default + link: false + third_party_settings: { } + region: content hidden: description: true langcode: true diff --git a/config/default/entity_browser.browser.h_svg_browser.yml b/config/default/entity_browser.browser.h_svg_browser.yml new file mode 100644 index 00000000..5c365e3c --- /dev/null +++ b/config/default/entity_browser.browser.h_svg_browser.yml @@ -0,0 +1,41 @@ +uuid: 68dee19a-be2c-42cd-a039-47ac146ecffb +langcode: en +status: true +dependencies: + config: + - media.type.h_svg + module: + - dropzonejs_eb_widget + - media +name: h_svg_browser +label: 'SVG Browser' +display: modal +display_configuration: + width: '650' + height: '500' + link_text: 'Select entities' + auto_open: false +selection_display: no_display +selection_display_configuration: { } +widget_selector: tabs +widget_selector_configuration: { } +widgets: + b17dba3f-64ab-4040-90e2-1395ab207aff: + settings: + media_type: h_svg + upload_location: 'public://[date:custom:Y]-[date:custom:m]' + dropzone_description: 'Drop files here to upload them' + max_filesize: 256M + extensions: svg + clientside_resize: false + resize_width: null + resize_height: null + resize_quality: !!float 1 + resize_method: contain + thumbnail_method: contain + submit_text: 'Select entities' + auto_select: false + uuid: b17dba3f-64ab-4040-90e2-1395ab207aff + weight: 1 + label: Upload + id: dropzonejs_media_entity diff --git a/config/default/field.field.media.h_svg.field_media_file.yml b/config/default/field.field.media.h_svg.field_media_file.yml new file mode 100644 index 00000000..a068b59a --- /dev/null +++ b/config/default/field.field.media.h_svg.field_media_file.yml @@ -0,0 +1,27 @@ +uuid: 7f7101ae-dfa9-4c71-af14-857d63978171 +langcode: en +status: true +dependencies: + config: + - field.storage.media.field_media_file + - media.type.h_svg + module: + - file +id: media.h_svg.field_media_file +field_name: field_media_file +entity_type: media +bundle: h_svg +label: File +description: '' +required: true +translatable: true +default_value: { } +default_value_callback: '' +settings: + file_directory: '[date:custom:Y]-[date:custom:m]' + file_extensions: svg + max_filesize: '' + description_field: false + handler: 'default:file' + handler_settings: { } +field_type: file diff --git a/config/default/field.field.taxonomy_term.h_notification_type.field_h_icon.yml b/config/default/field.field.taxonomy_term.h_notification_type.field_h_icon.yml new file mode 100644 index 00000000..900b8858 --- /dev/null +++ b/config/default/field.field.taxonomy_term.h_notification_type.field_h_icon.yml @@ -0,0 +1,29 @@ +uuid: 183ddbfe-be41-45b2-96ed-b2e512bf4276 +langcode: en +status: true +dependencies: + config: + - field.storage.taxonomy_term.field_h_icon + - media.type.h_svg + - taxonomy.vocabulary.h_notification_type +id: taxonomy_term.h_notification_type.field_h_icon +field_name: field_h_icon +entity_type: taxonomy_term +bundle: h_notification_type +label: 'Notification icon' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + handler: 'default:media' + handler_settings: + target_bundles: + h_svg: h_svg + sort: + field: name + direction: ASC + auto_create: false + auto_create_bundle: '' +field_type: entity_reference diff --git a/config/default/field.storage.taxonomy_term.field_h_icon.yml b/config/default/field.storage.taxonomy_term.field_h_icon.yml new file mode 100644 index 00000000..cfae68e8 --- /dev/null +++ b/config/default/field.storage.taxonomy_term.field_h_icon.yml @@ -0,0 +1,20 @@ +uuid: 31f6c07e-5ecd-4eb9-a583-9219334057f0 +langcode: en +status: true +dependencies: + module: + - media + - taxonomy +id: taxonomy_term.field_h_icon +field_name: field_h_icon +entity_type: taxonomy_term +type: entity_reference +settings: + target_type: media +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/default/language.content_settings.media.h_svg.yml b/config/default/language.content_settings.media.h_svg.yml new file mode 100644 index 00000000..c9c5ac59 --- /dev/null +++ b/config/default/language.content_settings.media.h_svg.yml @@ -0,0 +1,11 @@ +uuid: bc73e542-7d21-45ca-a705-a218dd133fd6 +langcode: en +status: true +dependencies: + config: + - media.type.h_svg +id: media.h_svg +target_entity_type_id: media +target_bundle: h_svg +default_langcode: site_default +language_alterable: false diff --git a/config/default/media.type.h_svg.yml b/config/default/media.type.h_svg.yml new file mode 100644 index 00000000..1ae00dd3 --- /dev/null +++ b/config/default/media.type.h_svg.yml @@ -0,0 +1,20 @@ +uuid: 8a7d112a-b4d9-43f7-becf-e1315d1641e3 +langcode: en +status: true +dependencies: + module: + - crop +third_party_settings: + crop: + image_field: _none +id: h_svg +label: SVG +description: 'Contains a SVG file.' +source: file +queue_thumbnail_downloads: false +new_revision: false +source_configuration: + source_field: field_media_file + thumbnails_directory: 'public://oembed_thumbnails' + providers: { } +field_map: { } diff --git a/dev_modules/custom/health_sample_content/migrations/health_sample_content.media.svg.yml b/dev_modules/custom/health_sample_content/migrations/health_sample_content.media.svg.yml new file mode 100644 index 00000000..21e08500 --- /dev/null +++ b/dev_modules/custom/health_sample_content/migrations/health_sample_content.media.svg.yml @@ -0,0 +1,41 @@ +id: sample_media_svg +label: Sample Media - SVG +migration_tags: + - health_sample_content + - health_sample_media + - health_sample_media_svg +source: + plugin: embedded_data + data_rows: + - id: 8 + image: 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/unicode.svg' + ids: + id: + type: string +process: + pseudo_destination_filename: + - plugin: callback + callable: basename + source: image + - plugin: skip_on_empty + method: row + message: 'Cannot import empty filename.' + pseudo_destionation_path: + - plugin: concat + source: + - '@pseudo_destination_filename' + name: '@pseudo_destination_filename' + 'field_media_file/target_id': + plugin: migration_lookup + migration: sample_file_document + source: id + uid: + plugin: default_value + default_value: 1 +destination: + plugin: 'entity:media' + default_bundle: h_svg +migration_dependencies: + required: + - sample_media_file + - sample_file_document diff --git a/dev_modules/custom/health_sample_content/migrations/health_sample_content.taxonomy.notification_type.yml b/dev_modules/custom/health_sample_content/migrations/health_sample_content.taxonomy.notification_type.yml index a14812c7..b705a090 100644 --- a/dev_modules/custom/health_sample_content/migrations/health_sample_content.taxonomy.notification_type.yml +++ b/dev_modules/custom/health_sample_content/migrations/health_sample_content.taxonomy.notification_type.yml @@ -10,6 +10,7 @@ source: id: h_notification_type_1 name: success field_h_colour: success + field_h_icon: 8 - id: h_notification_type_2 name: information @@ -31,9 +32,15 @@ process: migration: - sample_taxonomy_colour source: field_h_colour + field_h_icon/target_id: + plugin: migration_lookup + migration: sample_media_svg + source: field_h_icon + no_stub: true destination: plugin: entity:taxonomy_term default_bundle: h_notification_type dependencies: required: - sample_taxonomy_colour + - sample_media_svg diff --git a/dev_modules/custom/health_sample_content/migrations/migrate_plus.migration.health_sample_content.file.document.yml b/dev_modules/custom/health_sample_content/migrations/migrate_plus.migration.health_sample_content.file.document.yml index 80390200..1e0d9791 100644 --- a/dev_modules/custom/health_sample_content/migrations/migrate_plus.migration.health_sample_content.file.document.yml +++ b/dev_modules/custom/health_sample_content/migrations/migrate_plus.migration.health_sample_content.file.document.yml @@ -27,6 +27,9 @@ source: - id: 7 file: 'https://www.health.gov.au/sites/default/files/documents/2020/11/how-to-become-a-representative-for-someone-in-my-aged-care.docx' + - + id: 8 + file: 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/unicode.svg' ids: id: type: integer diff --git a/themes/health/health.theme b/themes/health/health.theme index 30fd2271..0e9f69e0 100644 --- a/themes/health/health.theme +++ b/themes/health/health.theme @@ -1488,21 +1488,25 @@ function health_preprocess_form_element(array &$variables) { * Implements template_preprocess_image(). */ function health_preprocess_image(array &$variables) { - // Lazy load images. - $variables['attributes']['data-src'] = $variables['attributes']['src']; - unset($variables['attributes']['src']); - // Calculate ratio for space reservation. - if (isset($variables['width']) && isset($variables['height'])) { - $variables['ratio'] = round(($variables['height'] / $variables['width']) * 100, 2); - } + if (isset($variables['attributes']['src'])) { + // Lazy load images. + $variables['attributes']['data-src'] = $variables['attributes']['src']; + unset($variables['attributes']['src']); + + // Calculate ratio for space reservation. + if (isset($variables['width']) && isset($variables['height'])) { + $variables['ratio'] = round(($variables['height'] / $variables['width']) * 100, 2); + } - // Set image alt property to null for decorative images. - $token = ''; - if (isset($variables['attributes']['alt']) && $variables['attributes']['alt'] === $token) { - $variables['alt'] = ''; - $variables['attributes']['alt'] = ''; + // Set image alt property to null for decorative images. + $token = ''; + if (isset($variables['attributes']['alt']) && $variables['attributes']['alt'] === $token) { + $variables['alt'] = ''; + $variables['attributes']['alt'] = ''; + } } + } /** @@ -1660,8 +1664,9 @@ function health_preprocess_node__h_global_notification(array &$variables) { } // Process notification background colour. - if ($node->hasField('field_h_notification_type')) { - /** @var \Drupal\taxonomy\TermInterface $colour. */ + if ($node->hasField('field_h_notification_type') && $node->get('field_h_notification_type')->entity) { + /** @var \Drupal\taxonomy\TermInterface $colour . */ + $colour = $node ->get('field_h_notification_type') ->entity @@ -1672,6 +1677,19 @@ function health_preprocess_node__h_global_notification(array &$variables) { ->value; $variables['health_notification_bg_colour'] = $colour_hex; $variables['health_dark_theme'] = ($colour->get('field_h_colour_theme')->value === 'dark') ? TRUE : FALSE; + + $notification = $node->get('field_h_notification_type')->entity; + if ($notification->hasField('field_h_icon') && $notification->get('field_h_icon') + ->isEmpty() !== TRUE) { + if ($icon = $notification->get('field_h_icon')->entity) { + + $media = Media::load($icon->mid->first()->value); + $fid = $media->field_media_file->target_id; + $file = File::load($fid); + $url = $file->url(); + $variables['health_notification_icon_url'] = $url; + } + } } } } diff --git a/themes/health/templates/content/node--h-global-notification.html.twig b/themes/health/templates/content/node--h-global-notification.html.twig index 647c9757..b1c5fe3b 100644 --- a/themes/health/templates/content/node--h-global-notification.html.twig +++ b/themes/health/templates/content/node--h-global-notification.html.twig @@ -82,7 +82,8 @@ "display_date": health_display_notification_date, "date": content.field_h_date_updated, "background_colour": health_notification_bg_colour, - "content": content.field_h_description + "content": content.field_h_description, + "icon_url": health_notification_icon_url, } %} diff --git a/themes/health/templates/custom/health-notification.html.twig b/themes/health/templates/custom/health-notification.html.twig index 844803a6..bf4eb80b 100644 --- a/themes/health/templates/custom/health-notification.html.twig +++ b/themes/health/templates/custom/health-notification.html.twig @@ -6,13 +6,19 @@ * @var content */ #} -
+
- - - + {% if icon_url %} + + {% else %} + + + + {% endif %}
{% if display_date == true %} @@ -23,9 +29,11 @@
{{ content }}
-