DeletedFieldsRepository.php in Drupal 9
File
core/lib/Drupal/Core/Field/DeletedFieldsRepository.php
View source
<?php
namespace Drupal\Core\Field;
use Drupal\Core\State\StateInterface;
class DeletedFieldsRepository implements DeletedFieldsRepositoryInterface {
protected $state;
public function __construct(StateInterface $state) {
$this->state = $state;
}
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;
}
public function getFieldStorageDefinitions() {
return $this->state
->get('field.storage.deleted', []);
}
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;
}
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;
}
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;
}
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;
}
}