isDeleted example


  public function buildForm(array $form, FormStateInterface $form_state) {
    $comment_count = $this->entityTypeManager->getStorage('comment')->getQuery()
      ->accessCheck(FALSE)
      ->condition('comment_type', $this->entity->id())
      ->count()
      ->execute();
    $entity_type = $this->entity->getTargetEntityTypeId();
    $caption = '';
    foreach (array_keys($this->commentManager->getFields($entity_type)) as $field_name) {
      /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
      if (($field_storage = FieldStorageConfig::loadByName($entity_type$field_name)) && $field_storage->getSetting('comment_type') == $this->entity->id() && !$field_storage->isDeleted()) {
        $caption .= '<p>' . $this->t('%label is used by the %field field on your site. You can not remove this comment type until you have removed the field.', [
          '%label' => $this->entity->label(),
          '%field' => $field_storage->label(),
        ]) . '</p>';
      }
    }

    if ($comment_count) {
      $caption .= '<p>' . $this->formatPlural($comment_count, '%label is used by 1 comment on your site. You can not remove this comment type until you have removed all of the %label comments.', '%label is used by @count comments on your site. You may not remove %label until you have removed all of the %label comments.', ['%label' => $this->entity->label()]) . '</p>';
    }
    if ($caption) {
      
static::initializeSandbox($context$config_importer);
    }

    // Get the list of field storages to purge.     $field_storages = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions']$config_importer->getUnprocessedConfiguration('delete'));
    // Get the first field storage to process.     $field_storage = reset($field_storages);
    if (!isset($context['sandbox']['field']['current_storage_id']) || $context['sandbox']['field']['current_storage_id'] != $field_storage->id()) {
      $context['sandbox']['field']['current_storage_id'] = $field_storage->id();
      // If the storage has not been deleted yet we need to do that. This is the       // case when the storage deletion is staged.       if (!$field_storage->isDeleted()) {
        $field_storage->delete();
      }
    }
    field_purge_batch($context['sandbox']['field']['purge_batch_size']$field_storage->getUniqueStorageIdentifier());
    $context['sandbox']['field']['current_progress']++;
    $fields_to_delete_count = count(static::getFieldStoragesToPurge($context['sandbox']['field']['extensions']$config_importer->getUnprocessedConfiguration('delete')));
    if ($fields_to_delete_count == 0) {
      $context['finished'] = 1;
    }
    else {
      $context['finished'] = $context['sandbox']['field']['current_progress'] / $context['sandbox']['field']['steps_to_delete'];
      

    // Create two fields for the same field storage so we can test that only one     // is deleted.     FieldConfig::create($this->fieldDefinition)->save();
    $another_field_definition = $this->fieldDefinition;
    $another_field_definition['bundle'] .= '_another_bundle';
    entity_test_create_bundle($another_field_definition['bundle']);
    FieldConfig::create($another_field_definition)->save();

    // Test that the first field is not deleted, and then delete it.     $field = current(\Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]));
    $this->assertFalse($field->isDeleted());
    $field->delete();

    // Make sure the field was deleted without being marked for purging as there     // was no data.     $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]);
    $this->assertCount(0, $fields, 'A deleted field is marked for deletion.');

    // Try to load the field normally and make sure it does not show up.     $field = FieldConfig::load('entity_test.' . '.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
    $this->assertTrue(empty($field), 'Field was deleted');

    
/** * {@inheritdoc} */
  public function validate($module) {
    $reasons = [];
    if ($field_storages = $this->getFieldStoragesByModule($module)) {
      // Provide an explanation message (only mention pending deletions if there       // remain no actual, non-deleted fields.)       $fields_in_use = [];
      foreach ($field_storages as $field_storage) {
        if (!$field_storage->isDeleted()) {
          $fields_in_use[$field_storage->getType()][] = $field_storage->getLabel();
        }
      }
      if (!empty($fields_in_use)) {
        foreach ($fields_in_use as $field_type => $field_storages) {
          $field_type_label = $this->getFieldTypeLabel($field_type);
          $reasons[] = $this->formatPlural(count($fields_in_use[$field_type]), 'The %field_type_label field type is used in the following field: @fields', 'The %field_type_label field type is used in the following fields: @fields', ['%field_type_label' => $field_type_label, '@fields' => implode(', ', $field_storages)]);
        }
      }
      else {
        $reasons[] = $this->t('Fields pending deletion');
      }
case 'field_id':
          case 'field_storage_uuid':
            $checked_value = $field_storage->uuid();
            break;

          case 'uuid';
            $checked_value = $field->uuid();
            break;

          case 'deleted';
            $checked_value = $field->isDeleted();
            break;

          default:
            $checked_value = $field->get($key);
            break;
        }

        // Skip to the next field as soon as one condition does not match.         if ($checked_value != $value) {
          continue 2;
        }
      }

  }

  /** * Deletes the schema for a field stored in a dedicated table. * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition * The storage definition of the field being deleted. */
  protected function deleteDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition) {
    $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]);
    $table_name = $table_mapping->getDedicatedDataTableName($storage_definition$storage_definition->isDeleted());
    if ($this->database->schema()->tableExists($table_name)) {
      $this->database->schema()->dropTable($table_name);
    }
    if ($this->entityType->isRevisionable()) {
      $revision_table_name = $table_mapping->getDedicatedRevisionTableName($storage_definition$storage_definition->isDeleted());
      if ($this->database->schema()->tableExists($revision_table_name)) {
        $this->database->schema()->dropTable($revision_table_name);
      }
    }
    $this->deleteFieldSchemaData($storage_definition);
  }

  

  public function getColumns() {
    $schema = $this->getSchema();
    return $schema['columns'];
  }

  /** * {@inheritdoc} */
  public function getBundles() {
    if (!$this->isDeleted()) {
      $map = \Drupal::service('entity_field.manager')->getFieldMap();
      if (isset($map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'])) {
        return $map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'];
      }
    }
    return [];
  }

  /** * {@inheritdoc} */
  
/** * Checks whether the given field can be stored in a shared table. * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition * The field storage definition. * * @return bool * TRUE if the field can be stored in a shared table, FALSE otherwise. */
  public function allowsSharedTableStorage(FieldStorageDefinitionInterface $storage_definition) {
    return !$storage_definition->hasCustomStorage() && $storage_definition->isBaseField() && !$storage_definition->isMultiple() && !$storage_definition->isDeleted();
  }

  /** * Checks whether the given field has to be stored in a dedicated table. * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition * The field storage definition. * * @return bool * TRUE if the field has to be stored in a dedicated table, FALSE otherwise. */
  
'cardinality' => 1,
    ]);
    $field_storage->save();
    FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => $bundle,
    ])->save();

    // The field still exists, deleted, with the same field name.     $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $deleted_field_uuid, 'include_deleted' => TRUE]);
    $this->assertArrayHasKey($deleted_field_uuid$fields);
    $this->assertTrue($fields[$deleted_field_uuid]->isDeleted());
    $this->assertSame($field_name$fields[$deleted_field_uuid]->getName());

    for ($i = 0; $i < 10; $i++) {
      $entity = $this->container->get('entity_type.manager')
        ->getStorage($this->entityTypeId)
        ->create(['type' => $bundle]);
      $entity->{$field_name}->setValue($this->_generateTestFieldValues(1));
      $entity->save();
    }

    // Check that the two field storages have different tables.
'entity_type' => 'entity_test',
      'bundle' => 'entity_test',
    ];
    FieldConfig::create($field_definition)->save();
    $another_field_definition = $field_definition;
    $another_field_definition['field_name'] = $another_field_storage_definition['field_name'];
    FieldConfig::create($another_field_definition)->save();

    // Test that the first field is not deleted, and then delete it.     $field_storage_config_storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
    $field_storage = current($field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]));
    $this->assertFalse($field_storage->isDeleted());
    FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();

    // Make sure that the field storage is deleted as it had no data.     $field_storages = $field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]);
    $this->assertCount(0, $field_storages, 'Field storage was deleted');

    // Make sure that this field is marked as deleted when it is     // specifically loaded.     $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE]);
    $this->assertCount(0, $fields, 'Field storage was deleted');

    

  public function onBundleDelete($bundle$entity_type_id) {}

  /** * {@inheritdoc} */
  protected function readFieldItemsToPurge(FieldDefinitionInterface $field_definition$batch_size) {
    // Check whether the whole field storage definition is gone, or just some     // bundle fields.     $storage_definition = $field_definition->getFieldStorageDefinition();
    $table_mapping = $this->getTableMapping();
    $table_name = $table_mapping->getDedicatedDataTableName($storage_definition$storage_definition->isDeleted());

    // Get the entities which we want to purge first.     $entity_query = $this->database->select($table_name, 't', ['fetch' => \PDO::FETCH_ASSOC]);
    $or = $entity_query->orConditionGroup();
    foreach ($storage_definition->getColumns() as $column_name => $data) {
      $or->isNotNull($table_mapping->getFieldColumnName($storage_definition$column_name));
    }
    $entity_query
      ->distinct(TRUE)
      ->fields('t', ['entity_id'])
      ->condition('bundle', $field_definition->getTargetBundle())
      
Home | Imprint | This part of the site doesn't use cookies.