setInternal example

class FileUriItem extends UriItem {

  /** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    $properties['url'] = DataDefinition::create('string')
      ->setLabel(t('Root-relative file URL'))
      ->setComputed(TRUE)
      ->setInternal(FALSE)
      ->setClass(ComputedFileUrl::class);

    return $properties;
  }

}
$properties['format'] = DataDefinition::create('filter_format')
      ->setLabel(t('Text format'))
      ->setSetting('allowed_formats', $field_definition->getSetting('allowed_formats'));

    $properties['processed'] = DataDefinition::create('string')
      ->setLabel(t('Processed text'))
      ->setDescription(t('The text with the text format applied.'))
      ->setComputed(TRUE)
      ->setClass('\Drupal\text\TextProcessed')
      ->setSetting('text source', 'value')
      ->setInternal(FALSE);

    return $properties;
  }

  /** * {@inheritdoc} */
  public function applyDefaultValue($notify = TRUE) {
    // @todo: Add in the filter default format here.     $this->setValue(['format' => NULL]$notify);
    return $this;
  }

  public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
    if ($this->workspaceManager->isEntityTypeSupported($entity_type)) {
      $field_name = $entity_type->getRevisionMetadataKey('workspace');
      $fields[$field_name] = BaseFieldDefinition::create('entity_reference')
        ->setLabel(new TranslatableMarkup('Workspace'))
        ->setDescription(new TranslatableMarkup('Indicates the workspace that this revision belongs to.'))
        ->setSetting('target_type', 'workspace')
        ->setInternal(TRUE)
        ->setTranslatable(FALSE)
        ->setRevisionable(TRUE);

      return $fields;
    }
  }

}
->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     // defined.     if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
      // The 'revision_translation_affected' field should always be defined.       // This field has been added unconditionally in Drupal 8.4.0 and it is       // overriding any pre-existing definition on purpose so that any       // differences are immediately available in the status report.
->setLabel(new TranslatableMarkup('Revision ID'))
        ->setReadOnly(TRUE)
        ->setSetting('unsigned', TRUE);

      $field_storage_definitions['revision_default'] = BaseFieldDefinition::create('boolean')
        ->setName('revision_default')
        ->setTargetEntityTypeId('entity_test_update')
        ->setTargetBundle(NULL)
        ->setLabel(new TranslatableMarkup('Default revision'))
        ->setDescription(new TranslatableMarkup('A flag indicating whether this was a default revision when it was saved.'))
        ->setStorageRequired(TRUE)
        ->setInternal(TRUE)
        ->setTranslatable(FALSE)
        ->setRevisionable(TRUE);
    }

    if ($translatable) {
      // The 'langcode' is already available for the 'entity_test_update' entity       // type because it has the 'langcode' entity key defined.       $field_storage_definitions['langcode']->setTranslatable(TRUE);

      $field_storage_definitions['default_langcode'] = BaseFieldDefinition::create('boolean')
        ->setName('default_langcode')
        
/** * Gets the base field definition for the 'workspace' revision metadata field. * * @return \Drupal\Core\Field\BaseFieldDefinition * The base field definition. */
  protected function getWorkspaceFieldDefinition() {
    return BaseFieldDefinition::create('entity_reference')
      ->setLabel($this->t('Workspace'))
      ->setDescription($this->t('Indicates the workspace that this revision belongs to.'))
      ->setSetting('target_type', 'workspace')
      ->setInternal(TRUE)
      ->setTranslatable(FALSE)
      ->setRevisionable(TRUE);
  }

}


  /** * {@inheritdoc} */
  protected function createEntity() {
    // Set flag so that internal field 'internal_string_field' is created.     // @see entity_test_entity_base_field_info()     $this->container->get('state')->set('entity_test.internal_field', TRUE);
    $field_storage_definition = BaseFieldDefinition::create('string')
      ->setLabel('Internal field')
      ->setInternal(TRUE);
    \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('internal_string_field', 'entity_test', 'entity_test', $field_storage_definition);

    $entity_test = EntityTest::create([
      'name' => 'Llama',
      'type' => 'entity_test',
      // Set a value for the internal field to confirm that it will not be       // returned in normalization.       // @see entity_test_entity_base_field_info().       'internal_string_field' => [
        'value' => 'This value shall not be internal!',
      ],
    ]);
/** * {@inheritdoc} */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties = parent::propertyDefinitions($field_definition);

    // Add a computed property that is non-internal.     $properties['non_internal_value'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Computed string, non-internal property'))
      ->setComputed(TRUE)
      ->setClass(ComputedString::class)
      ->setInternal(FALSE);
    // Add a computed property that is internal.     $properties['internal_value'] = DataDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Computed string, internal property'))
      ->setComputed(TRUE)
      ->setClass(ComputedString::class);
    return $properties;
  }

}
$fields['computed_reference_field'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel('Computed Reference Field Test')
      ->setComputed(TRUE)
      ->setSetting('target_type', 'entity_test')
      ->setClass(ComputedReferenceTestFieldItemList::class);

    $fields['computed_test_cacheable_string_field'] = BaseFieldDefinition::create('computed_test_cacheable_string_item')
      ->setLabel(new TranslatableMarkup('Computed Cacheable String Field Test'))
      ->setComputed(TRUE)
      ->setClass(ComputedTestCacheableStringItemList::class)
      ->setReadOnly(FALSE)
      ->setInternal(FALSE);

    return $fields;
  }

}
Home | Imprint | This part of the site doesn't use cookies.