public function TextFieldEmbedBase::process in Group Media 8.2
Search for the attached media entities.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity to search in.
Return value
\Drupal\media\MediaInterface[] Found media items.
Overrides MediaFinderInterface::process
File
- src/
Plugin/ MediaFinder/ TextFieldEmbedBase.php, line 77
Class
- TextFieldEmbedBase
- Class TextFieldEmbedBase.
Namespace
Drupal\groupmedia\Plugin\MediaFinderCode
public function process(EntityInterface $entity) {
$items = [];
if ($entity instanceof ContentEntityInterface) {
// Loop through all fields on the entity.
foreach ($entity
->getFieldDefinitions() as $key => $field) {
// Check if the field is an entity reference, referencing media entities,
// and retriever the media entity.
if (in_array($field
->getType(), $this
->getApplicableFieldTypes()) && !$entity
->get($key)
->isEmpty()) {
foreach ($entity
->get($key)
->getIterator() as $item) {
$media_entities = $this
->getTargetEntities($item);
$items = array_merge($items, $media_entities);
}
}
}
}
return $items;
}