public function BaseUpdateRunner::getEntityReferenceTargetIds in Scheduled Updates 8
Get target entity ids for an entity reference field on a entity.
@todo Is there a way to do this with core Field API?
@todo move this to a Utils trait or class.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity:
$field_name:
bool $sort:
Return value
array Entity Ids for field values. Entity Ids for field values.
Overrides UpdateRunnerInterface::getEntityReferenceTargetIds
3 calls to BaseUpdateRunner::getEntityReferenceTargetIds()
- BaseUpdateRunner::removeUpdate in src/
Plugin/ BaseUpdateRunner.php - Remove update from reference field value.
- EmbeddedUpdateRunner::getEmbeddedUpdates in src/
Plugin/ UpdateRunner/ EmbeddedUpdateRunner.php - Return all schedule updates that are referenced via Entity Reference fields.
- EmbeddedUpdateRunner::getUpdateIdsOnEntity in src/
Plugin/ UpdateRunner/ EmbeddedUpdateRunner.php - Get all update ids for this connected Update type.
File
- src/
Plugin/ BaseUpdateRunner.php, line 559 - Contains \Drupal\scheduled_updates\Plugin\BaseUpdateRunner.
Class
Namespace
Drupal\scheduled_updates\PluginCode
public function getEntityReferenceTargetIds(ContentEntityInterface $entity, $field_name, $sort = FALSE) {
$target_ids = [];
if ($entity
->hasField($field_name)) {
$field_values = $entity
->get($field_name)
->getValue();
foreach ($field_values as $field_value) {
$target_ids[] = $field_value['target_id'];
}
}
if ($sort) {
asort($target_ids);
}
return $target_ids;
}