protected function CorrespondingReference::entityHasValue in Corresponding Entity References 8.4
Checks if the given entity has the provided corresponding value.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to check.
string $fieldName: The field name on the entity to check.
mixed $id: The corresponding ID to check.
Return value
bool TRUE if value already exists, FALSE otherwise.
1 call to CorrespondingReference::entityHasValue()
- CorrespondingReference::calculateDifferences in src/
Entity/ CorrespondingReference.php - Return added and removed entities from the provided field.
File
- src/
Entity/ CorrespondingReference.php, line 430
Class
- CorrespondingReference
- Defines a corresponding reference entity.
Namespace
Drupal\cer\EntityCode
protected function entityHasValue(FieldableEntityInterface $entity, $fieldName, $id) {
if (!$entity
->hasField($fieldName)) {
return FALSE;
}
foreach ($entity
->get($fieldName) as $fieldItem) {
if ($fieldItem->target_id == $id) {
return TRUE;
}
}
return FALSE;
}