class SettingsSaveEventSubscriber in Content locking (anti-concurrent editing) 8.2
Same name and namespace in other branches
- 8 src/EventSubscriber/SettingsSaveEventSubscriber.php \Drupal\content_lock\EventSubscriber\SettingsSaveEventSubscriber
Class acts on config save event.
Hierarchy
- class \Drupal\content_lock\EventSubscriber\SettingsSaveEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of SettingsSaveEventSubscriber
1 string reference to 'SettingsSaveEventSubscriber'
1 service uses SettingsSaveEventSubscriber
File
- src/
EventSubscriber/ SettingsSaveEventSubscriber.php, line 13
Namespace
Drupal\content_lock\EventSubscriberView source
class SettingsSaveEventSubscriber implements EventSubscriberInterface {
protected $entityTypeManager;
/**
* SettingsSaveEventSubscriber constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* On config save.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The save event.
*/
public function onSave(ConfigCrudEvent $event) {
if ($event
->getConfig()
->getName() == 'content_lock.settings') {
foreach (array_filter($event
->getConfig()
->get('types')) as $type => $value) {
// Skip if the entity type does not exist.
if (!$this->entityTypeManager
->getDefinition($type, FALSE)) {
continue;
}
// Create an action config for all activated entity types.
$action = $this->entityTypeManager
->getStorage('action')
->loadByProperties([
'plugin' => 'entity:break_lock:' . $type,
]);
if (empty($action)) {
$action = $this->entityTypeManager
->getStorage('action')
->create([
'id' => $type . '_break_lock_action',
'label' => 'Break lock ' . $type,
'plugin' => 'entity:break_lock:' . $type,
'type' => $type,
]);
$action
->save();
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::SAVE][] = [
'onSave',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SettingsSaveEventSubscriber:: |
protected | property | ||
SettingsSaveEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
SettingsSaveEventSubscriber:: |
public | function | On config save. | |
SettingsSaveEventSubscriber:: |
public | function | SettingsSaveEventSubscriber constructor. |