AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber.php in Lingotek Translation 3.6.x
File
src/EventSubscriber/AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber.php
View source
<?php
namespace Drupal\lingotek\EventSubscriber;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
$events['serialize_content_entity_field'][] = [
'onSerializeContentField',
1001,
];
return $events;
}
public function onSerializeContentField(SerializeCdfEntityFieldEvent $event) {
$field = $event
->getField();
if (!$this
->includeField($field)) {
$event
->setExcluded();
$event
->stopPropagation();
}
}
protected function includeField(FieldItemListInterface $field) {
$definition = $field
->getFieldDefinition();
if ($definition
->getType() === 'entity_reference' && $field
->getSetting('target_type') === 'lingotek_content_metadata') {
return FALSE;
}
return TRUE;
}
}