class DateRecurEntityHooks in Recurring Dates Field 8
Reacts to Drupal entity hooks.
Hierarchy
- class \Drupal\date_recur\DateRecurEntityHooks
Expanded class hierarchy of DateRecurEntityHooks
1 string reference to 'DateRecurEntityHooks'
1 service uses DateRecurEntityHooks
File
- src/
DateRecurEntityHooks.php, line 12
Namespace
Drupal\date_recurView source
class DateRecurEntityHooks {
/**
* Provides the Date recur occurrence handler plugin manager.
*
* @var \Drupal\date_recur\Plugin\DateRecurOccurrenceHandlerManagerInterface
*/
protected $dateRecurOccurrenceManager;
/**
* Constructs a new DateRecurEntityHooks.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $dateRecurOccurrenceManager
* Provides the Date recur occurrence handler plugin manager.
*/
public function __construct(PluginManagerInterface $dateRecurOccurrenceManager) {
$this->dateRecurOccurrenceManager = $dateRecurOccurrenceManager;
}
/**
* Reacts to an inserted field storage config entity.
*
* @param \Drupal\field\FieldStorageConfigInterface $fieldStorageConfig
* Field storage config.
*
* @see \date_recur_field_storage_config_insert()
*
* @throws \Exception
* Throws exceptions.
*/
public function fieldStorageConfigInsert(FieldStorageConfigInterface $fieldStorageConfig) {
if ($fieldStorageConfig
->getType() != 'date_recur') {
return;
}
$this
->getInstanceFromDefinition($fieldStorageConfig)
->onFieldCreate($fieldStorageConfig);
}
/**
* Reacts to an updated field storage config entity.
*
* @param \Drupal\field\FieldStorageConfigInterface $fieldStorageConfig
* Field storage config.
*
* @throws \Exception
* Throws exceptions.
*
* @see \date_recur_field_storage_config_update()
*/
public function fieldStorageConfigUpdate(FieldStorageConfigInterface $fieldStorageConfig) {
if ($fieldStorageConfig
->getType() != 'date_recur') {
return;
}
$this
->getInstanceFromDefinition($fieldStorageConfig)
->onFieldUpdate($fieldStorageConfig);
}
/**
* Reacts to a deleted field storage config entity.
*
* @param \Drupal\field\FieldStorageConfigInterface $fieldStorageConfig
* Field storage config.
*
* @throws \Exception
* Throws exceptions.
*
* @see \date_recur_field_storage_config_delete()
*/
public function fieldStorageConfigDelete(FieldStorageConfigInterface $fieldStorageConfig) {
if ($fieldStorageConfig
->getType() != 'date_recur') {
return;
}
$this
->getInstanceFromDefinition($fieldStorageConfig)
->onFieldDelete($fieldStorageConfig);
}
/**
* Get an occurrence handler for a field definition.
*
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface $fieldStorageConfig
* Field storage config.
*
* @return \Drupal\date_recur\Plugin\DateRecurOccurrenceHandlerInterface
* A date recur occurrence handler instance.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
* If the instance cannot be created, such as if the ID is invalid.
*/
protected function getInstanceFromDefinition(FieldStorageDefinitionInterface $fieldStorageConfig) {
if ($fieldStorageConfig
->getType() != 'date_recur') {
throw new \InvalidArgumentException("Expected field of type date_recur.");
}
$pluginName = $fieldStorageConfig
->getSetting('occurrence_handler_plugin');
return $this->dateRecurOccurrenceManager
->createInstance($pluginName);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateRecurEntityHooks:: |
protected | property | Provides the Date recur occurrence handler plugin manager. | |
DateRecurEntityHooks:: |
public | function | Reacts to a deleted field storage config entity. | |
DateRecurEntityHooks:: |
public | function | Reacts to an inserted field storage config entity. | |
DateRecurEntityHooks:: |
public | function | Reacts to an updated field storage config entity. | |
DateRecurEntityHooks:: |
protected | function | Get an occurrence handler for a field definition. | |
DateRecurEntityHooks:: |
public | function | Constructs a new DateRecurEntityHooks. |