public function EntityReferenceHandlerBase::push in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::push()
- 2.0.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::push()
Parameters
\Drupal\cms_content_sync\SyncIntent $intent:
Return value
bool Whether or not the content has been pushed. FALSE is a desired state, meaning the entity should not be pushed according to config.
Throws
\Drupal\cms_content_sync\Exception\SyncException
Overrides FieldHandlerBase::push
File
- src/
Plugin/ EntityReferenceHandlerBase.php, line 223
Class
- EntityReferenceHandlerBase
- Providing a base implementation for any reference field type.
Namespace
Drupal\cms_content_sync\PluginCode
public function push(PushIntent $intent) {
$action = $intent
->getAction();
/**
* @var \Drupal\Core\Entity\EntityInterface $entity
*/
$entity = $intent
->getEntity();
// Deletion doesn't require any action on field basis for static data.
if (SyncIntent::ACTION_DELETE == $action) {
return false;
}
$data = $entity
->get($this->fieldName)
->getValue();
$result = [];
foreach ($data as $delta => $value) {
$reference = $this
->loadReferencedEntityFromFieldValue($value);
if (!$reference || $reference
->uuid() == $intent
->getUuid()) {
continue;
}
unset($value['target_id']);
$result[] = $this
->serializeReference($intent, $reference, $value);
}
$intent
->setProperty($this->fieldName, $result);
return true;
}