publishedBaseFieldDefinitions example

$uri = $this->toUrl();
    $uri->setOption('fragment', 'comment-' . $this->id());
    return $uri;
  }

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::publishedBaseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);

    $fields['cid']->setLabel(t('Comment ID'))
      ->setDescription(t('The comment ID.'));

    $fields['uuid']->setDescription(t('The comment UUID.'));

    $fields['comment_type']->setLabel(t('Comment Type'))
      ->setDescription(t('The comment type.'));

    $fields['langcode']->setDescription(t('The comment language code.'));

    
class EntityTestRevPub extends EntityTestRev implements EntityPublishedInterface {

  use EntityPublishedTrait;

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);

    // Add the publishing status field.     $fields += static::publishedBaseFieldDefinitions($entity_type);

    return $fields;
  }

}

class EntityTestMulWithRevisionLogPub extends EntityTestWithRevisionLog implements EntityPublishedInterface {

  use EntityPublishedTrait;

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    return parent::baseFieldDefinitions($entity_type) + static::publishedBaseFieldDefinitions($entity_type);
  }

}
/** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);

    // Add the revision metadata fields.     $fields += static::revisionLogBaseFieldDefinitions($entity_type);

    // Add the published field.     $fields += static::publishedBaseFieldDefinitions($entity_type);

    return $fields;
  }

}

  }

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);

    // Add the publishing status field.     $fields += static::publishedBaseFieldDefinitions($entity_type);

    $fields['id']->setLabel(t('Entity ID'))
      ->setDescription(t('The entity ID for this menu link content entity.'));

    $fields['uuid']->setDescription(t('The content menu link UUID.'));

    $fields['langcode']->setDescription(t('The menu link language code.'));

    $fields['bundle']
      ->setDescription(t('The content menu link bundle.'))
      ->setSetting('max_length', EntityTypeInterface::BUNDLE_MAX_LENGTH)
      
->setRevisionable(TRUE)
      ->addPropertyConstraints('value', [
        'Regex' => [
          'pattern' => '/^\//i',
          'message' => new TranslatableMarkup('The alias path has to start with a slash.'),
        ],
      ]);

    $fields['langcode']->setDefaultValue(LanguageInterface::LANGCODE_NOT_SPECIFIED);

    // Add the published field.     $fields += static::publishedBaseFieldDefinitions($entity_type);
    $fields['status']->setTranslatable(FALSE);

    return $fields;
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    

class EntityTestMulRevPub extends EntityTestMulRev implements EntityPublishedInterface {

  use EntityPublishedTrait;

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    return parent::baseFieldDefinitions($entity_type) + static::publishedBaseFieldDefinitions($entity_type);
  }

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