Commit 17a39317 authored by Eric Bremner's avatar Eric Bremner Committed by Eric Bremner
Browse files

ISTWCMS-4704: adding logic for featured images on nodes

parent 1cb435f4
{% if not featured_image %}
{%
set classes = [
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
]
%}
<div{{ attributes.addClass(classes) }}>
{% if admin_label %}
<div class="uw-admin-label">{{ admin_label }}</div>
{% endif %}
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
{{ content }}
{% endblock %}
</div>
{% endif %}
......@@ -87,6 +87,14 @@
{{ attach_library('seven/classy.node') }}
{% if view_mode == 'full' %}
{% if node_data.sources %}
{% set featured_image = 'yes' %}
{% else %}
{% set featured_image = 'no' %}
{% endif %}
{% endif %}
{% embed '@layouts/node/node.twig' with {
'classes': classes,
'has_sidebar': sidebar ? 'Yes' : 'No'
......@@ -96,6 +104,7 @@
<div{{ content_attributes.addClass('node__content') }}>
{% include '@components/card/card--node/card--node.twig' with {
'node': node_data,
'featured_image': featured_image,
} %}
</div>
{% endblock %}
......
......@@ -393,6 +393,49 @@ function uw_fdsu_theme_resp_preprocess_node(&$variables) {
*/
function uw_fdsu_theme_resp_preprocess_block(&$variables) {
// Look at page title block to see if we have a featured image.
// If we do then, set variable to not show page title.
if ($variables['plugin_id'] == 'page_title_block') {
// Set the featured image variable to false, we will only
// change if there is a featured image.
$variables['featured_image'] = FALSE;
// Load the node.
$node = \Drupal::routeMatch()->getParameter('node');
// If there is a node, check that it has a featured image.
if ($node) {
// The UW service object.
$uwService = \Drupal::service('uw_cfg_common.uw_service');
// Set the node type.
$node_type = $node->getType();
// Get the list of content types that are allowed to have
// feature images from our service.
$featured_image = $uwService->uwGetFeaturedImageContentTypes();
// If node is allowed to have a featured image, make sure that
// node actually has an image.
if (in_array($node_type, array_keys($featured_image))) {
// Get the field name.
$field_name = $featured_image[$node_type];
// Get the image object values from the node.
$image = $node->$field_name->getValue();
// If there is an image present, set the variable so that
// the page title will not be displayed.
if ($image) {
$variables['featured_image'] = TRUE;
}
}
}
}
// If we are in layout builder (this is set much earlier in
// the page load process), then continue to look if we need
// to add the admin_label and css classes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment