protected function InstantArticleContentEntityNormalizer::getApplicableComponents in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 src/Normalizer/InstantArticleContentEntityNormalizer.php \Drupal\fb_instant_articles\Normalizer\InstantArticleContentEntityNormalizer::getApplicableComponents()
Helper function to get relevant components from an entity view display.
This feels like it should be more straight forward, but alas. The EntityViewDispaly object has a method getComponents(), which returns display options for all fields. We're only interested in those which are configurable, marked as visible, and not extra fields.
Parameters
\Drupal\Core\Entity\Entity\EntityViewDisplay $display: Entity view display config entity.
Return value
array Components that should be included in the Facebook Instant Article.
See also
\Drupal\field_layout\FieldLayoutBuilder::getFields()
1 call to InstantArticleContentEntityNormalizer::getApplicableComponents()
File
- src/
Normalizer/ InstantArticleContentEntityNormalizer.php, line 386
Class
- InstantArticleContentEntityNormalizer
- Facebook Instant Articles content entity normalizer.
Namespace
Drupal\fb_instant_articles\NormalizerCode
protected function getApplicableComponents(EntityViewDisplay $display) {
$components = $display
->getComponents();
// Get a list of all fields for the given entity view display.
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($display
->getTargetEntityTypeId(), $display
->getTargetBundle());
// Exclude any fields which have a non-configurable display.
$fields_to_exclude = array_filter($field_definitions, function (FieldDefinitionInterface $field_definition) {
return !$field_definition
->isDisplayConfigurable('view');
});
// Ignore any extra fields from the list of field definitions. Field
// definitions can have a non-configurable display, but all extra fields are
// always displayed. We may want to re-visit including extra fields in the
// future.
$extra_fields = $this->entityFieldManager
->getExtraFields($display
->getTargetEntityTypeId(), $display
->getTargetBundle());
$extra_fields = isset($extra_fields['display']) ? $extra_fields['display'] : [];
return array_diff_key($components, $fields_to_exclude, $extra_fields);
}