isRevisionable example

$this->assertBundleFieldSchema($revisionable);
  }

  /** * Asserts the revisionable characteristics of an entity type. * * @internal */
  protected function assertRevisionable(): void {
    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityDefinitionUpdateManager->getEntityType($this->entityTypeId);
    $this->assertTrue($entity_type->isRevisionable());

    // Check that the required field definitions of a revisionable entity type     // exists and are stored in the correct tables.     $revision_key = $entity_type->getKey('revision');
    $revision_default_key = $entity_type->getRevisionMetadataKey('revision_default');
    $revision_field = $this->entityDefinitionUpdateManager->getFieldStorageDefinition($revision_key$entity_type->id());
    $revision_default_field = $this->entityDefinitionUpdateManager->getFieldStorageDefinition($revision_default_key$entity_type->id());
    $this->assertNotNull($revision_field);
    $this->assertNotNull($revision_default_field);

    $database_schema = $this->database->schema();
    
return (string) $definition->getLabel();
    }$field_definitions);
    return $fields;
  }

  /** * {@inheritdoc} */
  public function getIds() {
    $id_key = $this->entityType->getKey('id');
    $ids[$id_key] = $this->getDefinitionFromEntity($id_key);
    if ($this->configuration['add_revision_id'] && $this->entityType->isRevisionable()) {
      $revision_key = $this->entityType->getKey('revision');
      $ids[$revision_key] = $this->getDefinitionFromEntity($revision_key);
    }
    if ($this->entityType->isTranslatable()) {
      $langcode_key = $this->entityType->getKey('langcode');
      $ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key);
    }
    return $ids;
  }

}
protected function initTableLayout() {
    // Reset table field values to ensure changes in the entity type definition     // are correctly reflected in the table layout.     $this->tableMapping = NULL;
    $this->revisionKey = NULL;
    $this->revisionTable = NULL;
    $this->dataTable = NULL;
    $this->revisionDataTable = NULL;

    $table_mapping = $this->getTableMapping();
    $this->baseTable = $table_mapping->getBaseTable();
    $revisionable = $this->entityType->isRevisionable();
    if ($revisionable) {
      $this->revisionKey = $this->entityType->getKey('revision') ?: 'revision_id';
      $this->revisionTable = $table_mapping->getRevisionTable();
    }
    $translatable = $this->entityType->isTranslatable();
    if ($translatable) {
      $this->dataTable = $table_mapping->getDataTable();
      $this->langcodeKey = $this->entityType->getKey('langcode');
      $this->defaultLangcodeKey = $this->entityType->getKey('default_langcode');
    }
    if ($revisionable && $translatable) {
      
 $entity_type_id] = explode(PluginBase::DERIVATIVE_SEPARATOR, $source->getPluginId());
    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);

    $this->assertArrayHasKey($entity_type->getKey('id')$ids);
    $ids_count_expected = 1;

    if ($entity_type->isTranslatable()) {
      $ids_count_expected++;
      $this->assertArrayHasKey($entity_type->getKey('langcode')$ids);
    }

    if ($entity_type->isRevisionable() && $configuration['add_revision_id']) {
      $ids_count_expected++;
      $this->assertArrayHasKey($entity_type->getKey('revision')$ids);
    }

    $this->assertCount($ids_count_expected$ids);
  }

  /** * Tests user source plugin. * * @dataProvider migrationConfigurationProvider */
    // of the mandatory "id" attribute in JSON:API), so we disable it in most     // cases.     // - exposing its revision ID as an attribute will compete with any profile     // defined meta members used for resource object versioning.     // @see http://jsonapi.org/format/#document-resource-identifier-objects     $id_field_name = $entity_type->getKey('id');
    $uuid_field_name = $entity_type->getKey('uuid');
    if ($uuid_field_name && $uuid_field_name !== 'id') {
      $fields[$uuid_field_name] = new ResourceTypeAttribute($uuid_field_name, NULL, FALSE);
    }
    $fields[$id_field_name] = new ResourceTypeAttribute($id_field_name, "drupal_internal__$id_field_name");
    if ($entity_type->isRevisionable() && ($revision_id_field_name = $entity_type->getKey('revision'))) {
      $fields[$revision_id_field_name] = new ResourceTypeAttribute($revision_id_field_name, "drupal_internal__$revision_id_field_name");
    }
    if ($entity_type instanceof ConfigEntityTypeInterface) {
      // The '_core' key is reserved by Drupal core to handle complex edge cases       // correctly. Data in the '_core' key is irrelevant to clients reading       // configuration, and is not allowed to be set by clients writing       // configuration: it is for Drupal core only, and managed by Drupal core.       // @see https://www.drupal.org/node/2653358       $fields['_core'] = new ResourceTypeAttribute('_core', NULL, FALSE);
    }

    

  public function __construct(ContentEntityTypeInterface $entity_type, array $storage_definitions$prefix = '') {
    $this->entityType = $entity_type;
    $this->fieldStorageDefinitions = $storage_definitions;
    $this->prefix = $prefix;

    // @todo Remove table names from the entity type definition in     // https://www.drupal.org/node/2232465.     $this->baseTable = $this->prefix . $entity_type->getBaseTable() ?: $entity_type->id();
    if ($entity_type->isRevisionable()) {
      $this->revisionTable = $this->prefix . $entity_type->getRevisionTable() ?: $entity_type->id() . '_revision';
    }
    if ($entity_type->isTranslatable()) {
      $this->dataTable = $this->prefix . $entity_type->getDataTable() ?: $entity_type->id() . '_field_data';
    }
    if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
      $this->revisionDataTable = $this->prefix . $entity_type->getRevisionDataTable() ?: $entity_type->id() . '_field_revision';
    }
  }

  /** * Initializes the table mapping. * * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type * The entity type definition. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions * A list of field storage definitions that should be available for the * field columns of this table mapping. * @param string $prefix * (optional) A prefix to be used by all the tables of this mapping. * Defaults to an empty string. * * @return static * * @internal */
'field_widget_id' => $field_widget_id,
      'entity_type_id' => $entity->getEntityTypeId(),
      'bundle' => $entity->bundle(),
      'field_name' => $field_name,
    ];
    // Only add the entity ID when we actually have one. The entity ID needs to     // be a string to ensure that the media library state generates its     // tamper-proof hash in a consistent way.     if (!$entity->isNew()) {
      $opener_parameters['entity_id'] = (string) $entity->id();

      if ($entity->getEntityType()->isRevisionable()) {
        $opener_parameters['revision_id'] = (string) $entity->getRevisionId();
      }
    }
    $state = MediaLibraryState::create('media_library.opener.field_widget', $allowed_media_type_ids$selected_type_id$remaining$opener_parameters);

    // Add a button that will load the Media library in a modal using AJAX.     $element['open_button'] = [
      '#type' => 'button',
      '#value' => $this->t('Add media'),
      '#name' => $field_name . '-media-library-open-button' . $id_suffix,
      '#attributes' => [
        
/** @var \Drupal\Core\Entity\EntityStorageInterface $original_storage */
    $original_storage = $this->entityTypeManager->createHandlerInstance($original->getStorageClass()$original);
    $has_data = $original_storage->hasData();

    // If 'progress' is not set, then this will be the first run of the batch.     if (!isset($sandbox['progress'])) {
      // We cannot support updating the schema of an entity type from       // revisionable to non-revisionable or translatable to non-translatable       // because that can lead to unintended data loss.       // @todo Add support for these conversions in case there is no data loss.       // @see https://www.drupal.org/project/drupal/issues/3024727       $convert_rev_to_non_rev = $original->isRevisionable() && !$entity_type->isRevisionable();
      $convert_mul_to_non_mul = $original->isTranslatable() && !$entity_type->isTranslatable();
      if ($has_data && ($convert_rev_to_non_rev || $convert_mul_to_non_mul)) {
        throw new EntityStorageException('Converting an entity type from revisionable to non-revisionable or from translatable to non-translatable is not supported.');
      }

      // Check that the fields required by a revisionable entity type exist.       if ($entity_type->isRevisionable() && !isset($field_storage_definitions[$entity_type->getKey('revision')])) {
        throw new EntityStorageException('Missing revision field.');
      }
      if ($entity_type->isRevisionable() && !isset($field_storage_definitions[$entity_type->getRevisionMetadataKey('revision_default')])) {
        throw new EntityStorageException('Missing revision_default field.');
      }
      if (!isset($base_field_definitions[$keys['default_langcode']])) {
        $base_field_definitions[$keys['default_langcode']] = BaseFieldDefinition::create('boolean')
          ->setLabel($this->t('Default translation'))
          ->setDescription($this->t('A flag indicating whether this is the default translation.'))
          ->setTranslatable(TRUE)
          ->setRevisionable(TRUE)
          ->setDefaultValue(TRUE);
      }
    }

    // Make sure that revisionable entity types are correctly defined.     if ($entity_type->isRevisionable()) {
      $field_name = $entity_type->getRevisionMetadataKey('revision_default');
      $base_field_definitions[$field_name] = BaseFieldDefinition::create('boolean')
        ->setLabel($this->t('Default revision'))
        ->setDescription($this->t('A flag indicating whether this was a default revision when it was saved.'))
        ->setStorageRequired(TRUE)
        ->setInternal(TRUE)
        ->setTranslatable(FALSE)
        ->setRevisionable(TRUE);
    }

    // Make sure that revisionable and translatable entity types are correctly
$field_storage = $field_storage_definitions[$specifier];
        $column = $field_storage->getMainPropertyName();
      }
      else {
        $field_storage = FALSE;
        $column = NULL;
      }

      // If there is revision support, all the revisions are being queried, and       // the field is revisionable or the revision ID field itself, then use the       // revision ID. Otherwise, the entity ID will do.       $query_revisions = $all_revisions && $field_storage && ($field_storage->isRevisionable() || $field_storage->getName() === $entity_type->getKey('revision'));
      if ($query_revisions) {
        // This contains the relevant SQL field to be used when joining entity         // tables.         $entity_id_field = $entity_type->getKey('revision');
        // This contains the relevant SQL field to be used when joining field         // tables.         $field_id_field = 'revision_id';
      }
      else {
        $entity_id_field = $entity_type->getKey('id');
        $field_id_field = 'entity_id';
      }
return $this->fieldStorageDefinitions;
  }

  /** * {@inheritdoc} */
  public function getViewsData() {
    $data = [];

    $base_table = $this->entityType->getBaseTable() ?: $this->entityType->id();
    $views_revision_base_table = NULL;
    $revisionable = $this->entityType->isRevisionable();
    $entity_id_key = $this->entityType->getKey('id');
    $entity_keys = $this->entityType->getKeys();

    $revision_table = '';
    if ($revisionable) {
      $revision_table = $this->entityType->getRevisionTable() ?: $this->entityType->id() . '_revision';
    }

    $translatable = $this->entityType->isTranslatable();
    $data_table = '';
    if ($translatable) {
      

  }

  /** * Updates the 'entity_test_update' entity type to translatable. * * @param bool $perform_update * (optional) Whether the change should be performed by the entity * definition update manager. */
  protected function updateEntityTypeToTranslatable($perform_update = FALSE) {
    $revisionable = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update')->isRevisionable();

    $updated_entity_type = $this->getUpdatedEntityTypeDefinition($revisionable, TRUE);
    $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions($revisionable, TRUE);

    if ($perform_update) {
      $this->entityDefinitionUpdateManager->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions);
    }
  }

  /** * Updates the 'entity_test_update' entity type to not translatable. * * @param bool $perform_update * (optional) Whether the change should be performed by the entity * definition update manager. */
$this->assertFalse($definition->isTranslatable());
  }

  /** * Tests field revisionable methods. * * @covers ::isRevisionable * @covers ::setRevisionable */
  public function testFieldRevisionable() {
    $definition = BaseFieldDefinition::create($this->fieldType);
    $this->assertFalse($definition->isRevisionable());
    $definition->setRevisionable(TRUE);
    $this->assertTrue($definition->isRevisionable());
    $definition->setRevisionable(FALSE);
    $this->assertFalse($definition->isRevisionable());
  }

  /** * Tests field cardinality. * * @covers ::getCardinality * @covers ::setCardinality */
    // possible in the constructor.     $data = isset($values[$this->getEntityType()->getKey('id')]) ? ['status' => static::TRANSLATION_EXISTING] : ['status' => static::TRANSLATION_CREATED];
    $this->translations[LanguageInterface::LANGCODE_DEFAULT] = $data;
    $this->setDefaultLangcode();
    if ($translations) {
      foreach ($translations as $langcode) {
        if ($langcode != $this->defaultLangcode && $langcode != LanguageInterface::LANGCODE_DEFAULT) {
          $this->translations[$langcode] = $data;
        }
      }
    }
    if ($this->getEntityType()->isRevisionable()) {
      // Store the loaded revision ID the entity has been loaded with to       // keep it safe from changes.       $this->updateLoadedRevisionId();
    }
  }

  /** * {@inheritdoc} */
  protected function getLanguages() {
    if (empty($this->languages)) {
      
case 'revision_id':
        $field = BaseFieldDefinition::create('integer')
          ->setLabel('Revision ID')
          ->setReadOnly(TRUE)
          ->setSetting('unsigned', TRUE);
        break;

      case 'langcode':
        $field = BaseFieldDefinition::create('language')
          ->setLabel('Language');
        if ($entity_type->isRevisionable()) {
          $field->setRevisionable(TRUE);
        }
        if ($entity_type->isTranslatable()) {
          $field->setTranslatable(TRUE);
        }
        break;
    }

    $field
      ->setName($field_name)
      ->setTargetEntityTypeId($entity_type_id)
      
Home | Imprint | This part of the site doesn't use cookies.