Commit d8c19835 authored by catch's avatar catch

Issue #2846013 by Sam152: Use consistent case for the word "workflow" in content_moderation

parent 80ffa8c7
...@@ -54,7 +54,7 @@ public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface ...@@ -54,7 +54,7 @@ public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface
/* @var \Drupal\node\Entity\NodeType $entity */ /* @var \Drupal\node\Entity\NodeType $entity */
$entity = $form_state->getFormObject()->getEntity(); $entity = $form_state->getFormObject()->getEntity();
if ($this->moderationInfo->getWorkFlowForEntity($entity)) { if ($this->moderationInfo->getWorkflowForEntity($entity)) {
// Force the revision checkbox on. // Force the revision checkbox on.
$form['workflow']['options']['#default_value']['revision'] = 'revision'; $form['workflow']['options']['#default_value']['revision'] = 'revision';
$form['workflow']['options']['revision']['#disabled'] = TRUE; $form['workflow']['options']['revision']['#disabled'] = TRUE;
......
...@@ -101,7 +101,7 @@ public function entityPresave(EntityInterface $entity) { ...@@ -101,7 +101,7 @@ public function entityPresave(EntityInterface $entity) {
} }
if ($entity->moderation_state->value) { if ($entity->moderation_state->value) {
$workflow = $this->moderationInfo->getWorkFlowForEntity($entity); $workflow = $this->moderationInfo->getWorkflowForEntity($entity);
/** @var \Drupal\content_moderation\ContentModerationState $current_state */ /** @var \Drupal\content_moderation\ContentModerationState $current_state */
$current_state = $workflow->getState($entity->moderation_state->value); $current_state = $workflow->getState($entity->moderation_state->value);
...@@ -154,7 +154,7 @@ public function entityUpdate(EntityInterface $entity) { ...@@ -154,7 +154,7 @@ public function entityUpdate(EntityInterface $entity) {
*/ */
protected function updateOrCreateFromEntity(EntityInterface $entity) { protected function updateOrCreateFromEntity(EntityInterface $entity) {
$moderation_state = $entity->moderation_state->value; $moderation_state = $entity->moderation_state->value;
$workflow = $this->moderationInfo->getWorkFlowForEntity($entity); $workflow = $this->moderationInfo->getWorkflowForEntity($entity);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
if (!$moderation_state) { if (!$moderation_state) {
$moderation_state = $workflow->getInitialState()->id(); $moderation_state = $workflow->getInitialState()->id();
......
...@@ -64,7 +64,7 @@ public function getFormId() { ...@@ -64,7 +64,7 @@ public function getFormId() {
*/ */
public function buildForm(array $form, FormStateInterface $form_state, ContentEntityInterface $entity = NULL) { public function buildForm(array $form, FormStateInterface $form_state, ContentEntityInterface $entity = NULL) {
$current_state = $entity->moderation_state->value; $current_state = $entity->moderation_state->value;
$workflow = $this->moderationInfo->getWorkFlowForEntity($entity); $workflow = $this->moderationInfo->getWorkflowForEntity($entity);
/** @var \Drupal\workflows\Transition[] $transitions */ /** @var \Drupal\workflows\Transition[] $transitions */
$transitions = $this->validation->getValidTransitions($entity, $this->currentUser()); $transitions = $this->validation->getValidTransitions($entity, $this->currentUser());
...@@ -133,7 +133,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -133,7 +133,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('The moderation state has been updated.')); drupal_set_message($this->t('The moderation state has been updated.'));
$new_state = $this->moderationInfo->getWorkFlowForEntity($entity)->getState($new_state); $new_state = $this->moderationInfo->getWorkflowForEntity($entity)->getState($new_state);
// The page we're on likely won't be visible if we just set the entity to // The page we're on likely won't be visible if we just set the entity to
// the default state, as we hide that latest-revision tab if there is no // the default state, as we hide that latest-revision tab if there is no
// forward revision. Redirect to the canonical URL instead, since that will // forward revision. Redirect to the canonical URL instead, since that will
......
...@@ -130,7 +130,7 @@ public function hasForwardRevision(ContentEntityInterface $entity) { ...@@ -130,7 +130,7 @@ public function hasForwardRevision(ContentEntityInterface $entity) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isLiveRevision(ContentEntityInterface $entity) { public function isLiveRevision(ContentEntityInterface $entity) {
$workflow = $this->getWorkFlowForEntity($entity); $workflow = $this->getWorkflowForEntity($entity);
return $this->isLatestRevision($entity) return $this->isLatestRevision($entity)
&& $entity->isDefaultRevision() && $entity->isDefaultRevision()
&& $entity->moderation_state->value && $entity->moderation_state->value
...@@ -140,7 +140,7 @@ public function isLiveRevision(ContentEntityInterface $entity) { ...@@ -140,7 +140,7 @@ public function isLiveRevision(ContentEntityInterface $entity) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getWorkFlowForEntity(ContentEntityInterface $entity) { public function getWorkflowForEntity(ContentEntityInterface $entity) {
$bundles = $this->bundleInfo->getBundleInfo($entity->getEntityTypeId()); $bundles = $this->bundleInfo->getBundleInfo($entity->getEntityTypeId());
if (isset($bundles[$entity->bundle()]['workflow'])) { if (isset($bundles[$entity->bundle()]['workflow'])) {
return $this->entityTypeManager->getStorage('workflow')->load($bundles[$entity->bundle()]['workflow']); return $this->entityTypeManager->getStorage('workflow')->load($bundles[$entity->bundle()]['workflow']);
......
...@@ -135,6 +135,6 @@ public function isLiveRevision(ContentEntityInterface $entity); ...@@ -135,6 +135,6 @@ public function isLiveRevision(ContentEntityInterface $entity);
* @return \Drupal\workflows\WorkflowInterface|null * @return \Drupal\workflows\WorkflowInterface|null
* The workflow entity. NULL if there is no workflow. * The workflow entity. NULL if there is no workflow.
*/ */
public function getWorkFlowForEntity(ContentEntityInterface $entity); public function getWorkflowForEntity(ContentEntityInterface $entity);
} }
...@@ -116,7 +116,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ...@@ -116,7 +116,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
return $element + ['#access' => FALSE]; return $element + ['#access' => FALSE];
} }
$workflow = $this->moderationInformation->getWorkFlowForEntity($entity); $workflow = $this->moderationInformation->getWorkflowForEntity($entity);
$default = $items->get($delta)->value ? $workflow->getState($items->get($delta)->value) : $workflow->getInitialState(); $default = $items->get($delta)->value ? $workflow->getState($items->get($delta)->value) : $workflow->getInitialState();
if (!$default) { if (!$default) {
throw new \UnexpectedValueException(sprintf('The %s bundle has an invalid moderation state configuration, moderation states are enabled but no default is set.', $bundle_entity->label())); throw new \UnexpectedValueException(sprintf('The %s bundle has an invalid moderation state configuration, moderation states are enabled but no default is set.', $bundle_entity->label()));
......
...@@ -37,7 +37,7 @@ protected function getModerationStateId() { ...@@ -37,7 +37,7 @@ protected function getModerationStateId() {
// It is possible that the bundle does not exist at this point. For example, // It is possible that the bundle does not exist at this point. For example,
// the node type form creates a fake Node entity to get default values. // the node type form creates a fake Node entity to get default values.
// @see \Drupal\node\NodeTypeForm::form() // @see \Drupal\node\NodeTypeForm::form()
$workflow = $moderation_info->getWorkFlowForEntity($entity); $workflow = $moderation_info->getWorkflowForEntity($entity);
return $workflow ? $workflow->getInitialState()->id() : NULL; return $workflow ? $workflow->getInitialState()->id() : NULL;
} }
...@@ -60,7 +60,7 @@ protected function loadContentModerationStateRevision(ContentEntityInterface $en ...@@ -60,7 +60,7 @@ protected function loadContentModerationStateRevision(ContentEntityInterface $en
// Ensure the correct revision is loaded in scenarios where a revision is // Ensure the correct revision is loaded in scenarios where a revision is
// being reverted. // being reverted.
->condition('content_entity_revision_id', $entity->isNewRevision() ? $entity->getLoadedRevisionId() : $entity->getRevisionId()) ->condition('content_entity_revision_id', $entity->isNewRevision() ? $entity->getLoadedRevisionId() : $entity->getRevisionId())
->condition('workflow', $moderation_info->getWorkFlowForEntity($entity)->id()) ->condition('workflow', $moderation_info->getWorkflowForEntity($entity)->id())
->allRevisions() ->allRevisions()
->sort('revision_id', 'DESC') ->sort('revision_id', 'DESC')
->execute(); ->execute();
......
...@@ -92,7 +92,7 @@ public function validate($value, Constraint $constraint) { ...@@ -92,7 +92,7 @@ public function validate($value, Constraint $constraint) {
$original_entity = $original_entity->getTranslation($entity->language()->getId()); $original_entity = $original_entity->getTranslation($entity->language()->getId());
} }
$workflow = $this->moderationInformation->getWorkFlowForEntity($entity); $workflow = $this->moderationInformation->getWorkflowForEntity($entity);
$new_state = $workflow->getState($entity->moderation_state->value) ?: $workflow->getInitialState(); $new_state = $workflow->getState($entity->moderation_state->value) ?: $workflow->getInitialState();
$original_state = $workflow->getState($original_entity->moderation_state->value); $original_state = $workflow->getState($original_entity->moderation_state->value);
// @todo - what if $new_state references something that does not exist or // @todo - what if $new_state references something that does not exist or
......
...@@ -39,7 +39,7 @@ public function __construct(ModerationInformationInterface $moderation_info) { ...@@ -39,7 +39,7 @@ public function __construct(ModerationInformationInterface $moderation_info) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) { public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) {
$workflow = $this->moderationInfo->getWorkFlowForEntity($entity); $workflow = $this->moderationInfo->getWorkflowForEntity($entity);
$current_state = $entity->moderation_state->value ? $workflow->getState($entity->moderation_state->value) : $workflow->getInitialState(); $current_state = $entity->moderation_state->value ? $workflow->getState($entity->moderation_state->value) : $workflow->getInitialState();
return array_filter($current_state->getTransitions(), function(Transition $transition) use ($workflow, $user) { return array_filter($current_state->getTransitions(), function(Transition $transition) use ($workflow, $user) {
......
...@@ -82,9 +82,9 @@ public function testIsModeratedEntity($workflow, $expected) { ...@@ -82,9 +82,9 @@ public function testIsModeratedEntity($workflow, $expected) {
/** /**
* @dataProvider providerWorkflow * @dataProvider providerWorkflow
* @covers ::getWorkFlowForEntity * @covers ::getWorkflowForEntity
*/ */
public function testGetWorkFlowForEntity($workflow) { public function testGetWorkflowForEntity($workflow) {
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
if ($workflow) { if ($workflow) {
$workflow_entity = $this->prophesize(WorkflowInterface::class)->reveal(); $workflow_entity = $this->prophesize(WorkflowInterface::class)->reveal();
...@@ -100,7 +100,7 @@ public function testGetWorkFlowForEntity($workflow) { ...@@ -100,7 +100,7 @@ public function testGetWorkFlowForEntity($workflow) {
$entity->getEntityTypeId()->willReturn('test_entity_type'); $entity->getEntityTypeId()->willReturn('test_entity_type');
$entity->bundle()->willReturn('test_bundle'); $entity->bundle()->willReturn('test_bundle');
$this->assertEquals($workflow_entity, $moderation_information->getWorkFlowForEntity($entity->reveal())); $this->assertEquals($workflow_entity, $moderation_information->getWorkflowForEntity($entity->reveal()));
} }
/** /**
......
...@@ -78,7 +78,7 @@ protected function setUpModerationInformation(ContentEntityInterface $entity) { ...@@ -78,7 +78,7 @@ protected function setUpModerationInformation(ContentEntityInterface $entity) {
->addTransition('review', 'review', ['draft'], 'needs_review') ->addTransition('review', 'review', ['draft'], 'needs_review')
->addTransition('publish', 'publish', ['needs_review', 'published'], 'published'); ->addTransition('publish', 'publish', ['needs_review', 'published'], 'published');
$moderation_info = $this->prophesize(ModerationInformationInterface::class); $moderation_info = $this->prophesize(ModerationInformationInterface::class);
$moderation_info->getWorkFlowForEntity($entity)->willReturn($workflow); $moderation_info->getWorkflowForEntity($entity)->willReturn($workflow);
return $moderation_info->reveal(); return $moderation_info->reveal();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment