Example #1
0
 /**
  * Returns an array of transition permissions.
  *
  * @return array
  *   The transition permissions.
  */
 public function transitionPermissions()
 {
     // @todo https://www.drupal.org/node/2779933 write a test for this.
     $perms = [];
     /* @var \Drupal\content_moderation\ModerationStateInterface[] $states */
     $states = ModerationState::loadMultiple();
     /* @var \Drupal\content_moderation\ModerationStateTransitionInterface $transition */
     foreach (ModerationStateTransition::loadMultiple() as $id => $transition) {
         $perms['use ' . $id . ' transition'] = ['title' => $this->t('Use the %transition_name transition', ['%transition_name' => $transition->label()]), 'description' => $this->t('Move content from %from state to %to state.', ['%from' => $states[$transition->getFromState()]->label(), '%to' => $states[$transition->getToState()]->label()])];
     }
     return $perms;
 }
 /**
  * Tests content moderation third party schema for block content types.
  */
 public function testContentModerationBlockContentTypeConfig()
 {
     $this->installEntitySchema('block_content');
     $this->installEntitySchema('user');
     $this->installConfig(['content_moderation']);
     $typed_config = \Drupal::service('config.typed');
     $moderation_states = ModerationState::loadMultiple();
     $block_content_type = BlockContentType::create(['id' => 'basic', 'label' => 'basic', 'revision' => TRUE]);
     $block_content_type->setThirdPartySetting('content_moderation', 'enabled', TRUE);
     $block_content_type->setThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($moderation_states));
     $block_content_type->setThirdPartySetting('content_moderation', 'default_moderation_state', '');
     $block_content_type->save();
     $this->assertConfigSchema($typed_config, $block_content_type->getEntityType()->getConfigPrefix() . '.' . $block_content_type->id(), $block_content_type->toArray());
 }
 /**
  * Enable moderation for a specified content type, using the UI.
  *
  * @param string $content_type_id
  *   Machine name.
  * @param string[] $allowed_states
  *   Array of allowed state IDs.
  * @param string $default_state
  *   Default state.
  */
 protected function enableModerationThroughUi($content_type_id, array $allowed_states, $default_state)
 {
     $this->drupalGet('admin/structure/types');
     $this->assertLinkByHref('admin/structure/types/manage/' . $content_type_id . '/moderation');
     $this->drupalGet('admin/structure/types/manage/' . $content_type_id);
     $this->assertLinkByHref('admin/structure/types/manage/' . $content_type_id . '/moderation');
     $this->drupalGet('admin/structure/types/manage/' . $content_type_id . '/moderation');
     $this->assertFieldByName('enable_moderation_state');
     $this->assertNoFieldChecked('edit-enable-moderation-state');
     $edit['enable_moderation_state'] = 1;
     /** @var ModerationState $state */
     foreach (ModerationState::loadMultiple() as $state) {
         $key = $state->isPublishedState() ? 'allowed_moderation_states_published[' . $state->id() . ']' : 'allowed_moderation_states_unpublished[' . $state->id() . ']';
         $edit[$key] = in_array($state->id(), $allowed_states, TRUE) ? $state->id() : FALSE;
     }
     $edit['default_moderation_state'] = $default_state;
     $this->drupalPostForm(NULL, $edit, t('Save'));
 }