class FilterFormatStorageController

Defines the storage controller class for Filter Format entities.

Hierarchy

Expanded class hierarchy of FilterFormatStorageController

File

drupal/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php, line 16
Contains \Drupal\filter\FilterFormatStorageController.

Namespace

Drupal\filter
View source
class FilterFormatStorageController extends ConfigStorageController {

  /**
   * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::preSave().
   */
  protected function preSave(EntityInterface $entity) {
    parent::preSave($entity);
    $entity->name = trim($entity
      ->label());

    // @todo Do not save disabled filters whose properties are identical to
    //   all default properties.
    // Determine whether the format can be cached.
    // @todo This is a derived/computed definition, not configuration.
    $entity->cache = TRUE;
    foreach ($entity
      ->filters() as $filter) {
      if ($filter->status && !$filter->cache) {
        $entity->cache = FALSE;
      }
    }
  }

  /**
   * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::postSave().
   */
  protected function postSave(EntityInterface $entity, $update) {
    parent::postSave($entity, $update);

    // Clear the static caches of filter_formats() and others.
    filter_formats_reset();
    if ($update) {

      // Clear the filter cache whenever a text format is updated.
      cache('filter')
        ->deleteTags(array(
        'filter_format' => $entity
          ->id(),
      ));
    }
    else {

      // Default configuration of modules and installation profiles is allowed
      // to specify a list of user roles to grant access to for the new format;
      // apply the defined user role permissions when a new format is inserted
      // and has a non-empty $roles property.
      // Note: user_role_change_permissions() triggers a call chain back into
      // filter_permission() and lastly filter_formats(), so its cache must be
      // reset upfront.
      if (($roles = $entity
        ->get('roles')) && ($permission = filter_permission_name($entity))) {
        foreach (user_roles() as $rid => $name) {
          $enabled = in_array($rid, $roles, TRUE);
          user_role_change_permissions($rid, array(
            $permission => $enabled,
          ));
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigStorageController::$configFactory protected property The config factory service.
ConfigStorageController::$configStorage protected property The config storage service.
ConfigStorageController::$statusKey protected property Name of the entity's status key or FALSE if a status is not supported.
ConfigStorageController::$uuidKey protected property Name of the entity's UUID property. Overrides EntityStorageControllerBase::$uuidKey
ConfigStorageController::attachLoad protected function Attaches data to entities upon loading. 4
ConfigStorageController::buildQuery protected function Builds the query to load the entity.
ConfigStorageController::create public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::create(). Overrides EntityStorageControllerInterface::create 2
ConfigStorageController::createInstance public static function Instantiates a new instance of this entity controller. Overrides EntityControllerInterface::createInstance 2
ConfigStorageController::delete public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::delete(). Overrides EntityStorageControllerInterface::delete
ConfigStorageController::deleteRevision public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::deleteRevision(). Overrides EntityStorageControllerInterface::deleteRevision
ConfigStorageController::getConfigPrefix public function Returns the config prefix used by the configuration entity type.
ConfigStorageController::getFieldDefinitions public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::getFieldDefinitions(). Overrides EntityStorageControllerInterface::getFieldDefinitions
ConfigStorageController::getIDFromConfigName public static function Extracts the configuration entity ID from the full configuration name.
ConfigStorageController::getQueryServicename public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServicename(). Overrides EntityStorageControllerInterface::getQueryServicename
ConfigStorageController::importCreate public function Create configuration upon synchronizing configuration changes. 1
ConfigStorageController::importDelete public function Delete configuration upon synchronizing configuration changes. 2
ConfigStorageController::importUpdate public function Updates configuration upon synchronizing configuration changes. 1
ConfigStorageController::invokeHook protected function Invokes a hook on behalf of the entity.
ConfigStorageController::load public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::load(). Overrides EntityStorageControllerInterface::load 2
ConfigStorageController::loadByProperties public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadByProperties(). Overrides EntityStorageControllerInterface::loadByProperties 2
ConfigStorageController::loadRevision public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadRevision(). Overrides EntityStorageControllerInterface::loadRevision
ConfigStorageController::postDelete protected function Acts on deleted entities before the delete hook is invoked. 5
ConfigStorageController::preDelete protected function Acts on entities before they are deleted. 3
ConfigStorageController::save public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::save(). Overrides EntityStorageControllerInterface::save
ConfigStorageController::__construct public function Constructs a ConfigStorageController object. Overrides EntityStorageControllerBase::__construct 2
EntityStorageControllerBase::$cache protected property Whether this entity type should use the static cache. 1
EntityStorageControllerBase::$entityCache protected property Static cache of entities.
EntityStorageControllerBase::$entityInfo protected property Array of information about the entity.
EntityStorageControllerBase::$entityType protected property Entity type for this controller instance.
EntityStorageControllerBase::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
EntityStorageControllerBase::$idKey protected property Name of the entity's ID field in the entity database table.
EntityStorageControllerBase::cacheGet protected function Gets entities from the static cache.
EntityStorageControllerBase::cacheSet protected function Stores entities in the static entity cache.
EntityStorageControllerBase::loadUnchanged public function Loads an unchanged entity from the database. Overrides EntityStorageControllerInterface::loadUnchanged
EntityStorageControllerBase::resetCache public function Resets the internal, static entity cache. Overrides EntityStorageControllerInterface::resetCache 3
FilterFormatStorageController::postSave protected function Overrides \Drupal\Core\Config\Entity\ConfigStorageController::postSave(). Overrides ConfigStorageController::postSave
FilterFormatStorageController::preSave protected function Overrides \Drupal\Core\Config\Entity\ConfigStorageController::preSave(). Overrides ConfigStorageController::preSave