public static function FieldExtractor::getFieldsFromEntity in Dependency Calculation 8
Extract all fields in all translations that match our criteria.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.
callable $condition: The condition.
Return value
\Drupal\Core\Field\FieldItemListInterface[] The list of fields.
7 calls to FieldExtractor::getFieldsFromEntity()
- DrupalMediaEmbedCollector::onCalculateDependencies in src/
EventSubscriber/ DependencyCollector/ DrupalMediaEmbedCollector.php - Calculates media entities embedded into the text areas of other entities.
- EntityEmbedCollector::extractEmbeddedEntities in src/
EventSubscriber/ DependencyCollector/ EntityEmbedCollector.php - Extracts embedded entities from the text fields of another entity.
- EntityLanguage::onCalculateDependencies in src/
EventSubscriber/ DependencyCollector/ EntityLanguage.php - Calculates the language of content entities.
- EntityReferenceFieldDependencyCollector::onCalculateDependencies in src/
EventSubscriber/ DependencyCollector/ EntityReferenceFieldDependencyCollector.php - Calculates the referenced entities.
- LayoutBuilderFieldDependencyCollector::onCalculateDependencies in src/
EventSubscriber/ DependencyCollector/ LayoutBuilderFieldDependencyCollector.php - Calculates the entities referenced on Layout Builder components.
File
- src/
FieldExtractor.php, line 24
Class
- FieldExtractor
- Class FieldExtractor.
Namespace
Drupal\depcalcCode
public static function getFieldsFromEntity(ContentEntityInterface $entity, callable $condition) {
$fields = [];
$languages = $entity
->getTranslationLanguages();
/**
* @var string $field_name
* @var \Drupal\Core\Field\FieldItemListInterface $field
*/
foreach ($entity as $field_name => $field) {
// Check if field definition type is a link.
if ($condition($entity, $field_name, $field)) {
// If the field is translatable get all translations of it.
if ($field
->getFieldDefinition()
->isTranslatable()) {
foreach ($languages as $language) {
$translated = $entity
->getTranslation($language
->getId());
$fields[] = $translated
->get($field_name);
}
}
else {
$fields[] = $field;
}
}
}
if ($fields) {
$event = new FilterDependencyCalculationFieldsEvent($entity, ...$fields);
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
$dispatcher = \Drupal::service('event_dispatcher');
$dispatcher
->dispatch(DependencyCalculatorEvents::FILTER_FIELDS, $event);
$fields = $event
->getFields();
}
return $fields;
}