You are here

class DateRecurEntityHooks in Recurring Dates Field 8

Reacts to Drupal entity hooks.

Hierarchy

Expanded class hierarchy of DateRecurEntityHooks

1 string reference to 'DateRecurEntityHooks'
date_recur.services.yml in ./date_recur.services.yml
date_recur.services.yml
1 service uses DateRecurEntityHooks
date_recur.entity_hooks in ./date_recur.services.yml
Drupal\date_recur\DateRecurEntityHooks

File

src/DateRecurEntityHooks.php, line 12

Namespace

Drupal\date_recur
View 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

Namesort descending Modifiers Type Description Overrides
DateRecurEntityHooks::$dateRecurOccurrenceManager protected property Provides the Date recur occurrence handler plugin manager.
DateRecurEntityHooks::fieldStorageConfigDelete public function Reacts to a deleted field storage config entity.
DateRecurEntityHooks::fieldStorageConfigInsert public function Reacts to an inserted field storage config entity.
DateRecurEntityHooks::fieldStorageConfigUpdate public function Reacts to an updated field storage config entity.
DateRecurEntityHooks::getInstanceFromDefinition protected function Get an occurrence handler for a field definition.
DateRecurEntityHooks::__construct public function Constructs a new DateRecurEntityHooks.