class LayoutBuilderFieldUnserializer in Acquia Content Hub 8.2
Layout builder field unserializer fallback subscriber.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\LayoutBuilderFieldUnserializer implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses LayoutBuilderDataHandlerTrait
Expanded class hierarchy of LayoutBuilderFieldUnserializer
1 string reference to 'LayoutBuilderFieldUnserializer'
1 service uses LayoutBuilderFieldUnserializer
File
- src/
EventSubscriber/ UnserializeContentField/ LayoutBuilderFieldUnserializer.php, line 14
Namespace
Drupal\acquia_contenthub\EventSubscriber\UnserializeContentFieldView source
class LayoutBuilderFieldUnserializer implements EventSubscriberInterface {
use LayoutBuilderDataHandlerTrait;
/**
* Layout section field type definition.
*
* @var string
*/
protected $fieldType = 'layout_section';
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* LayoutBuilderFieldSerializer constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::UNSERIALIZE_CONTENT_ENTITY_FIELD] = [
'onUnserializeContentField',
];
return $events;
}
/**
* Handling for Layout Builder sections.
*
* @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) {
$event_field_type = $event
->getFieldMetadata()['type'];
if ($event_field_type !== $this->fieldType) {
return;
}
$field = $event
->getField();
$values = [];
if (!empty($field['value'])) {
foreach ($field['value'] as $langcode => $sections) {
foreach ($this
->unserializeSections($sections) as $section) {
$values[$langcode][$event
->getFieldName()][] = [
'section' => $section,
];
}
}
$event
->setValue($values);
}
$event
->stopPropagation();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LayoutBuilderDataHandlerTrait:: |
protected | function | Gets configuration for a Layout Builder component. | |
LayoutBuilderDataHandlerTrait:: |
protected | function | Prepares component to be serialized. | |
LayoutBuilderDataHandlerTrait:: |
protected | function | Prepares Layout Builder sections to be serialized. | |
LayoutBuilderDataHandlerTrait:: |
protected | function | Prepares Layout Builder components to be unserialized. | |
LayoutBuilderDataHandlerTrait:: |
protected | function | Prepares Layout Builder sections to be unserialized. | |
LayoutBuilderFieldUnserializer:: |
protected | property |
The entity type manager. Overrides LayoutBuilderDataHandlerTrait:: |
|
LayoutBuilderFieldUnserializer:: |
protected | property | Layout section field type definition. | |
LayoutBuilderFieldUnserializer:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
LayoutBuilderFieldUnserializer:: |
public | function | Handling for Layout Builder sections. | |
LayoutBuilderFieldUnserializer:: |
public | function | LayoutBuilderFieldSerializer constructor. |