isModeratedEntityType example


  public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
    if (!$this->moderationInfo->isModeratedEntityType($entity_type)) {
      return [];
    }

    $fields = [];
    $fields['moderation_state'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Moderation state'))
      ->setDescription(t('The moderation state of this piece of content.'))
      ->setComputed(TRUE)
      ->setClass(ModerationStateFieldItemList::class)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        

  public function testIsModeratedEntityType() {
    $moderation_information = new ModerationInformation($this->getEntityTypeManager()$this->setupModerationBundleInfo('test_bundle', 'workflow'));

    $moderated_entity_type = $this->prophesize(EntityTypeInterface::class);
    $moderated_entity_type->id()->willReturn('test_entity_type');

    $unmoderated_entity_type = $this->prophesize(EntityTypeInterface::class);
    $unmoderated_entity_type->id()->willReturn('unmoderated_test_type');

    $this->assertTrue($moderation_information->isModeratedEntityType($moderated_entity_type->reveal()));
    $this->assertFalse($moderation_information->isModeratedEntityType($unmoderated_entity_type->reveal()));
  }

  /** * @dataProvider providerWorkflow * @covers ::isModeratedEntity */
  public function testIsModeratedEntity($workflow$expected) {
    $moderation_information = new ModerationInformation($this->getEntityTypeManager()$this->setupModerationBundleInfo('test_bundle', $workflow));

    $entity_type = new ContentEntityType([
      
/** * Returns the views data. * * @return array * The views data. */
  public function getViewsData() {
    $data = [];

    $entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions()function DEntityTypeInterface $type) {
      return $this->moderationInformation->isModeratedEntityType($type);
    });

    foreach ($entity_types_with_moderation as $entity_type) {
      $table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();

      $data[$table]['moderation_state'] = [
        'title' => t('Moderation state'),
        'field' => [
          'id' => 'moderation_state_field',
          'default_formatter' => 'content_moderation_state',
          'field_name' => 'moderation_state',
        ],
Home | Imprint | This part of the site doesn't use cookies.