class DeletedFieldsRepository

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/DeletedFieldsRepository.php \Drupal\Core\Field\DeletedFieldsRepository
  2. 10 core/lib/Drupal/Core/Field/DeletedFieldsRepository.php \Drupal\Core\Field\DeletedFieldsRepository
  3. 11.x core/lib/Drupal/Core/Field/DeletedFieldsRepository.php \Drupal\Core\Field\DeletedFieldsRepository

Provides a repository for deleted field and field storage objects.

@internal

Hierarchy

Expanded class hierarchy of DeletedFieldsRepository

1 string reference to 'DeletedFieldsRepository'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses DeletedFieldsRepository
entity_field.deleted_fields_repository in core/core.services.yml
Drupal\Core\Field\DeletedFieldsRepository

File

core/lib/Drupal/Core/Field/DeletedFieldsRepository.php, line 12

Namespace

Drupal\Core\Field
View source
class DeletedFieldsRepository implements DeletedFieldsRepositoryInterface {
    
    /**
     * The state key/value store.
     *
     * @var \Drupal\Core\State\StateInterface
     */
    protected $state;
    
    /**
     * Constructs a new deleted fields repository.
     *
     * @param \Drupal\Core\State\StateInterface $state
     *   The state key/value store.
     */
    public function __construct(StateInterface $state) {
        $this->state = $state;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getFieldDefinitions($field_storage_unique_id = NULL) {
        $deleted_field_definitions = $this->state
            ->get('field.field.deleted', []);
        if ($field_storage_unique_id) {
            $deleted_field_definitions = array_filter($deleted_field_definitions, function (FieldDefinitionInterface $field_definition) use ($field_storage_unique_id) {
                return $field_definition->getFieldStorageDefinition()
                    ->getUniqueStorageIdentifier() === $field_storage_unique_id;
            });
        }
        return $deleted_field_definitions;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getFieldStorageDefinitions() {
        return $this->state
            ->get('field.storage.deleted', []);
    }
    
    /**
     * {@inheritdoc}
     */
    public function addFieldDefinition(FieldDefinitionInterface $field_definition) {
        $deleted_field_definitions = $this->state
            ->get('field.field.deleted', []);
        $deleted_field_definitions[$field_definition->getUniqueIdentifier()] = $field_definition;
        $this->state
            ->set('field.field.deleted', $deleted_field_definitions);
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function addFieldStorageDefinition(FieldStorageDefinitionInterface $field_storage_definition) {
        $deleted_storage_definitions = $this->state
            ->get('field.storage.deleted', []);
        $deleted_storage_definitions[$field_storage_definition->getUniqueStorageIdentifier()] = $field_storage_definition;
        $this->state
            ->set('field.storage.deleted', $deleted_storage_definitions);
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function removeFieldDefinition(FieldDefinitionInterface $field_definition) {
        $deleted_field_definitions = $this->state
            ->get('field.field.deleted', []);
        unset($deleted_field_definitions[$field_definition->getUniqueIdentifier()]);
        $this->state
            ->set('field.field.deleted', $deleted_field_definitions);
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function removeFieldStorageDefinition(FieldStorageDefinitionInterface $field_storage_definition) {
        $deleted_storage_definitions = $this->state
            ->get('field.storage.deleted', []);
        unset($deleted_storage_definitions[$field_storage_definition->getUniqueStorageIdentifier()]);
        $this->state
            ->set('field.storage.deleted', $deleted_storage_definitions);
        return $this;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DeletedFieldsRepository::$state protected property The state key/value store.
DeletedFieldsRepository::addFieldDefinition public function Adds a field definition object to the deleted list. Overrides DeletedFieldsRepositoryInterface::addFieldDefinition
DeletedFieldsRepository::addFieldStorageDefinition public function Adds a field storage definition object to the deleted list. Overrides DeletedFieldsRepositoryInterface::addFieldStorageDefinition
DeletedFieldsRepository::getFieldDefinitions public function Returns a list of deleted field definitions. Overrides DeletedFieldsRepositoryInterface::getFieldDefinitions
DeletedFieldsRepository::getFieldStorageDefinitions public function Returns a list of deleted field storage definitions. Overrides DeletedFieldsRepositoryInterface::getFieldStorageDefinitions
DeletedFieldsRepository::removeFieldDefinition public function Removes a field definition object from the deleted list. Overrides DeletedFieldsRepositoryInterface::removeFieldDefinition
DeletedFieldsRepository::removeFieldStorageDefinition public function Removes a field storage definition object from the deleted list. Overrides DeletedFieldsRepositoryInterface::removeFieldStorageDefinition
DeletedFieldsRepository::__construct public function Constructs a new deleted fields repository.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.