class ConfigEntityWithNullUuid in Acquia Content Hub 8.2
Handles config entities with null uuids.
@package Drupal\acquia_contenthub_subscriber\EventSubscriber\PreEntitySave
Hierarchy
- class \Drupal\acquia_contenthub_subscriber\EventSubscriber\PreEntitySave\ConfigEntityWithNullUuid implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigEntityWithNullUuid
1 string reference to 'ConfigEntityWithNullUuid'
- acquia_contenthub_subscriber.services.yml in modules/
acquia_contenthub_subscriber/ acquia_contenthub_subscriber.services.yml - modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.services.yml
1 service uses ConfigEntityWithNullUuid
File
- modules/
acquia_contenthub_subscriber/ src/ EventSubscriber/ PreEntitySave/ ConfigEntityWithNullUuid.php, line 15
Namespace
Drupal\acquia_contenthub_subscriber\EventSubscriber\PreEntitySaveView source
class ConfigEntityWithNullUuid implements EventSubscriberInterface {
/**
* The module handler.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* ConfigEntityWithNullUuid constructor.
*/
public function __construct() {
$this->entityTypeManager = \Drupal::entityTypeManager();
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::PRE_ENTITY_SAVE] = 'onPreEntitySave';
return $events;
}
/**
* Saves a configuration entity to assign the UUID of an imported entity.
*
* @param \Drupal\acquia_contenthub\Event\PreEntitySaveEvent $event
* The pre entity save event.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function onPreEntitySave(PreEntitySaveEvent $event) {
$entity = $event
->getEntity();
if ($entity instanceof ConfigEntityInterface) {
$local_entity = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->load($entity
->id());
if ($local_entity && !$local_entity
->uuid()) {
$config_id = $entity
->getConfigDependencyName();
$config = \Drupal::configFactory()
->getEditable($config_id);
$config
->set('uuid', $event
->getCdf()
->getUuid());
$config
->save();
$entity
->set('uuid', $event
->getCdf()
->getUuid());
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityWithNullUuid:: |
protected | property | The module handler. | |
ConfigEntityWithNullUuid:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigEntityWithNullUuid:: |
public | function | Saves a configuration entity to assign the UUID of an imported entity. | |
ConfigEntityWithNullUuid:: |
public | function | ConfigEntityWithNullUuid constructor. |