class TextItemField in Acquia Content Hub 8.2
Manual handling for text item fields filter references.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\TextItemField implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses FieldEntityDependencyTrait
Expanded class hierarchy of TextItemField
1 string reference to 'TextItemField'
1 service uses TextItemField
File
- src/
EventSubscriber/ UnserializeContentField/ TextItemField.php, line 12
Namespace
Drupal\acquia_contenthub\EventSubscriber\UnserializeContentFieldView source
class TextItemField implements EventSubscriberInterface {
use FieldEntityDependencyTrait;
/**
* Field types to unserialize.
*
* @var array
*/
protected $fieldTypes = [
'text_with_summary',
'text',
'text_long',
];
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::UNSERIALIZE_CONTENT_ENTITY_FIELD] = [
'onUnserializeContentField',
100,
];
return $events;
}
/**
* Extract the stored filter_format uuid and retrieve the entity id.
*
* @param \Drupal\acquia_contenthub\Event\UnserializeCdfEntityFieldEvent $event
* The unserialize event.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function onUnserializeContentField(UnserializeCdfEntityFieldEvent $event) {
if (!in_array($event
->getFieldMetadata()['type'], $this->fieldTypes)) {
return;
}
$field = $event
->getField();
$values = [];
// Return early if no attr values are set.
if (empty($field['value'])) {
return;
}
foreach ($field['value'] as $langcode => $value) {
foreach ($value as $delta => &$item) {
if (!$item['format']) {
continue;
}
$filter = $this
->getEntity($item['format'], $event);
$item['format'] = $filter
->id();
}
$values[$langcode][$event
->getFieldName()] = $value;
}
$event
->setValue($values);
$event
->stopPropagation();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldEntityDependencyTrait:: |
protected | function | Get an entity from the dependency stack. | |
TextItemField:: |
protected | property | Field types to unserialize. | |
TextItemField:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
TextItemField:: |
public | function | Extract the stored filter_format uuid and retrieve the entity id. |