-
Notifications
You must be signed in to change notification settings - Fork 32
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
EWPP-287: Create organisation teaser #595
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
config: | ||
- core.entity_view_mode.node.teaser | ||
- field.field.node.oe_organisation.body | ||
- field.field.node.oe_organisation.oe_organisation_acronym | ||
- field.field.node.oe_organisation.oe_organisation_contact | ||
- field.field.node.oe_organisation.oe_organisation_logo | ||
- field.field.node.oe_organisation.oe_summary | ||
- field.field.node.oe_organisation.oe_teaser | ||
- image.style.oe_theme_ratio_3_2_medium | ||
- node.type.oe_organisation | ||
module: | ||
- oe_theme_helper | ||
- text | ||
- user | ||
id: node.oe_organisation.teaser | ||
targetEntityType: node | ||
bundle: oe_organisation | ||
mode: teaser | ||
content: | ||
extra_field_oe_theme_content_organisation_teaser_details: | ||
weight: 2 | ||
region: content | ||
settings: { } | ||
third_party_settings: { } | ||
oe_organisation_acronym: | ||
type: string | ||
weight: 0 | ||
region: content | ||
label: above | ||
settings: | ||
link_to_entity: false | ||
third_party_settings: { } | ||
oe_organisation_logo: | ||
type: oe_theme_helper_media_thumbnail_url | ||
weight: 3 | ||
region: content | ||
label: above | ||
settings: | ||
image_style: oe_theme_ratio_3_2_medium | ||
third_party_settings: { } | ||
oe_teaser: | ||
type: text_default | ||
weight: 1 | ||
region: content | ||
label: above | ||
settings: { } | ||
third_party_settings: { } | ||
hidden: | ||
body: true | ||
extra_field_oe_theme_helper_short_title_with_fallback: true | ||
langcode: true | ||
links: true | ||
oe_content_content_owner: true | ||
oe_content_legacy_link: true | ||
oe_content_navigation_title: true | ||
oe_content_short_title: true | ||
oe_organisation_contact: true | ||
oe_summary: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_theme_content_organisation\Plugin\ExtraField\Display; | ||
|
||
use Drupal\Core\Cache\CacheableMetadata; | ||
use Drupal\Core\Entity\ContentEntityInterface; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase; | ||
use Drupal\oe_content_entity_contact\Entity\ContactInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Display organisation details. | ||
* | ||
* @ExtraFieldDisplay( | ||
* id = "oe_theme_content_organisation_teaser_details", | ||
* label = @Translation("Teaser details"), | ||
* bundles = { | ||
* "node.oe_organisation", | ||
* }, | ||
* visible = true | ||
* ) | ||
*/ | ||
class TeaserDetailsExtraField extends ExtraFieldDisplayFormattedBase implements ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* The entity type manager. | ||
* | ||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface | ||
*/ | ||
protected $entityTypeManager; | ||
|
||
/** | ||
* TeaserDetailsExtraField constructor. | ||
* | ||
* @param array $configuration | ||
* A configuration array containing information about the plugin instance. | ||
* @param string $plugin_id | ||
* The plugin_id for the plugin instance. | ||
* @param mixed $plugin_definition | ||
* The plugin implementation definition. | ||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager | ||
* The entity type manager. | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
$this->entityTypeManager = $entity_type_manager; | ||
} | ||
|
||
/** | ||
* {@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') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function viewElements(ContentEntityInterface $entity) { | ||
// Return an empty array if empty, so the field can be considered empty. | ||
if ($entity->get('oe_organisation_contact')->isEmpty()) { | ||
return []; | ||
} | ||
|
||
$contact = $entity->get('oe_organisation_contact')->entity; | ||
if (!$contact instanceof ContactInterface) { | ||
return []; | ||
} | ||
|
||
$build = [ | ||
'#type' => 'pattern', | ||
'#id' => 'field_list', | ||
'#variant' => 'horizontal', | ||
'#fields' => [ | ||
'items' => [], | ||
], | ||
]; | ||
$cache = CacheableMetadata::createFromRenderArray($build); | ||
|
||
$contact_access = $contact->access('view', NULL, TRUE); | ||
$cache->addCacheableDependency($contact); | ||
$cache->addCacheableDependency($contact_access); | ||
|
||
if (!$contact_access->isAllowed()) { | ||
$cache->applyTo($build); | ||
return $build; | ||
} | ||
|
||
$items = []; | ||
$fields = [ | ||
'oe_website' => [], | ||
'oe_email' => ['type' => 'email_mailto'], | ||
'oe_phone' => [], | ||
'oe_address' => [ | ||
'type' => 'oe_theme_helper_address_inline', | ||
'settings' => ['delimiter' => ', '], | ||
], | ||
]; | ||
foreach ($fields as $field_name => $display_options) { | ||
if (!$contact->get($field_name)->isEmpty()) { | ||
$items[] = $this->getRenderableFieldListItem($contact, $field_name, $display_options); | ||
} | ||
ademarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
$build['#fields']['items'] = $items; | ||
$cache->applyTo($build); | ||
|
||
return $build; | ||
} | ||
|
||
/** | ||
* Get renderable item for field list pattern. | ||
* | ||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity | ||
* Content entity. | ||
* @param string $field_name | ||
* Field name. | ||
* @param array $display_options | ||
* Display options for field rendering. | ||
* | ||
* @return array | ||
* Renderable array. | ||
*/ | ||
protected function getRenderableFieldListItem(ContentEntityInterface $entity, string $field_name, array $display_options = []): array { | ||
$display_options += [ | ||
'label' => 'hidden', | ||
]; | ||
$renderable = $this->entityTypeManager->getViewBuilder('oe_contact') | ||
->viewField($entity->get($field_name), $display_options); | ||
|
||
return [ | ||
'label' => $renderable['#title'], | ||
'body' => $renderable, | ||
]; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{# | ||
/** | ||
* @file | ||
* Theme override to display a node of bundle organisation in the teaser view mode. | ||
*/ | ||
#} | ||
{% set image_url = content.oe_organisation_logo|field_value|render %} | ||
{{ pattern('list_item', { | ||
'variant': 'thumbnail_secondary', | ||
'url': url, | ||
'meta': [ | ||
content.oe_organisation_acronym|field_value, | ||
], | ||
'title': label, | ||
'detail': content.oe_teaser|field_value, | ||
'additional_information': [ | ||
content.extra_field_oe_theme_content_organisation_teaser_details, | ||
], | ||
'image': image_url ? { 'src': image_url } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not pass the alt value of the image here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not doing that anywhere actually, as the image is displayed as a background anyway and we want to refactor that into using media container. I'd postpone this to this follow up: EWPP-249 which has already some POC work done here #569 |
||
}) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current teaser view