Skip to content
Snippets Groups Projects

Feature/istwcms 4704 m26lebla ebremner content types

Merged Eric Bremner requested to merge feature/ISTWCMS-4704-m26lebla-ebremner-content-types into 1.0.x
1 file
+ 25
31
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,7 @@ namespace Drupal\uw_custom_blocks\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\uw_cfg_common\Service\UWServiceInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -25,6 +26,13 @@ class UwCblProfilesManual extends BlockBase implements ContainerFactoryPluginInt
*/
protected $entityTypeManager;
/**
* UW service.
*
* @var \Drupal\uw_cfg_common\Service\UWServiceInterface
*/
protected $uwService;
/**
* Constructs a BlockComponentRenderArray object.
*
@@ -36,17 +44,20 @@ class UwCblProfilesManual extends BlockBase implements ContainerFactoryPluginInt
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\uw_cfg_common\Service\UWServiceInterface $uwService
* UW Service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, UWServiceInterface $uwService) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
$this->uwService = $uwService;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager'));
return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager'), $container->get('uw_cfg_common.uw_service'));
}
/**
@@ -62,9 +73,6 @@ class UwCblProfilesManual extends BlockBase implements ContainerFactoryPluginInt
$show_title = $this->configuration['show_title'];
$show_image = $this->configuration['show_image'];
// Load in the image style.
$style = $this->entityTypeManager->getStorage('image_style')->load('thumbnail');
// Step through each profile and setup variable for template.
foreach ($profile_ids as $profile_id) {
@@ -78,37 +86,23 @@ class UwCblProfilesManual extends BlockBase implements ContainerFactoryPluginInt
continue;
}
// Reset the image field, if not we will continue to see
// the same image for each profile, in case some profiles
// do not contain an image.
$image = NULL;
// Get the teaser data.
$teaser = $this->uwService->uwGetNodeContent($node, 'teaser');
// If we are to show an image, get the image values.
if ($show_image) {
// Ensure that we have an image, get the image object.
if ($image_object = $node->field_uw_ct_profile_image->entity->field_media_image) {
// If we are not to show the image, set the image to null,
// so that it doesn't display.
if (!$show_image) {
$teaser['image'] = NULL;
}
// Setup the URL and alt tag.
$image = [
'url' => $style->buildUrl($image_object->entity->getFileUri()),
'alt' => $image_object->alt,
];
}
// If we are not to show the title, set the title to null,
// so that it doesn't display.
if (!$show_title) {
$teaser['title'] = NULL;
}
// Set profile variables in the array.
$profiles[$profile_id['weight']] = [
'url' => $node->toUrl()->toString(),
'title' => $show_title ? $node->getTitle() : '',
'position' => $node->field_uw_ct_profile_title->value,
'image' => $image,
'summary' => [
'#type' => 'processed_text',
'#text' => $node->field_uw_profile_summary->value,
'#format' => 'uw_tf_standard',
],
];
$profiles[$profile_id['weight']] = $teaser;
}
// Return custom template with variable.
Loading