updated core to 8.6.1 via composer

This commit is contained in:
2018-09-12 13:58:26 +02:00
parent a9a219f2ed
commit ea56b9fba3
4443 changed files with 112098 additions and 40708 deletions
@@ -16,6 +16,12 @@ use Drupal\workflows\WorkflowInterface;
* id = "workflow",
* label = @Translation("Workflow"),
* label_collection = @Translation("Workflows"),
* label_singular = @Translation("workflow"),
* label_plural = @Translation("workflows"),
* label_count = @PluralTranslation(
* singular = "@count workflow",
* plural = "@count workflows",
* ),
* handlers = {
* "access" = "Drupal\workflows\WorkflowAccessControlHandler",
* "list_builder" = "Drupal\workflows\WorkflowListBuilder",
@@ -86,13 +86,13 @@ class WorkflowAddForm extends EntityForm {
$workflow = $this->entity;
$return = $workflow->save();
if (empty($workflow->getTypePlugin()->getStates())) {
drupal_set_message($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
$this->messenger()->addStatus($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
'%label' => $workflow->label(),
]));
$form_state->setRedirectUrl($workflow->toUrl('add-state-form'));
}
else {
drupal_set_message($this->t('Created the %label Workflow.', [
$this->messenger()->addStatus($this->t('Created the %label Workflow.', [
'%label' => $workflow->label(),
]));
$form_state->setRedirectUrl($workflow->toUrl('edit-form'));
@@ -53,7 +53,7 @@ class WorkflowDeleteForm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t(
$this->messenger()->addStatus($this->t(
'Workflow %label deleted.',
['%label' => $this->entity->label()]
));
@@ -77,7 +77,7 @@ class WorkflowEditForm extends EntityForm {
$header = [
'state' => $this->t('State'),
'weight' => $this->t('Weight'),
'operations' => $this->t('Operations')
'operations' => $this->t('Operations'),
];
$form['states_container'] = [
'#type' => 'details',
@@ -103,28 +103,28 @@ class WorkflowEditForm extends EntityForm {
// Warn the user if there are no states.
if (empty($states)) {
drupal_set_message(
$this->messenger()->addWarning(
$this->t(
'This workflow has no states and will be disabled until there is at least one, <a href=":add-state">add a new state.</a>',
[':add-state' => $workflow->toUrl('add-state-form')->toString()]
),
'warning'
)
);
}
$state_weight_delta = round(count($states) / 2);
foreach ($states as $state) {
$links = [
'edit' => [
'title' => $this->t('Edit'),
'url' => Url::fromRoute('entity.workflow.edit_state_form', ['workflow' => $workflow->id(), 'workflow_state' => $state->id()]),
]
],
];
if ($this->entity->access('delete-state:' . $state->id())) {
$links['delete'] = [
'title' => t('Delete'),
'url' => Url::fromRoute('entity.workflow.delete_state_form', [
'workflow' => $workflow->id(),
'workflow_state' => $state->id()
'workflow_state' => $state->id(),
]),
];
}
@@ -138,6 +138,7 @@ class WorkflowEditForm extends EntityForm {
'#title_display' => 'invisible',
'#default_value' => $state->weight(),
'#attributes' => ['class' => ['state-weight']],
'#delta' => $state_weight_delta,
],
'operations' => [
'#type' => 'operations',
@@ -154,7 +155,7 @@ class WorkflowEditForm extends EntityForm {
'weight' => $this->t('Weight'),
'from' => $this->t('From'),
'to' => $this->t('To'),
'operations' => $this->t('Operations')
'operations' => $this->t('Operations'),
];
$form['transitions_container'] = [
'#type' => 'details',
@@ -174,7 +175,10 @@ class WorkflowEditForm extends EntityForm {
],
],
];
foreach ($workflow->getTypePlugin()->getTransitions() as $transition) {
$transitions = $workflow->getTypePlugin()->getTransitions();
$transition_weight_delta = round(count($transitions) / 2);
foreach ($transitions as $transition) {
$links['edit'] = [
'title' => $this->t('Edit'),
'url' => Url::fromRoute('entity.workflow.edit_transition_form', ['workflow' => $workflow->id(), 'workflow_transition' => $transition->id()]),
@@ -193,6 +197,7 @@ class WorkflowEditForm extends EntityForm {
'#title_display' => 'invisible',
'#default_value' => $transition->weight(),
'#attributes' => ['class' => ['transition-weight']],
'#delta' => $transition_weight_delta,
],
'from' => [
'#theme' => 'item_list',
@@ -255,7 +260,7 @@ class WorkflowEditForm extends EntityForm {
}
$workflow->save();
drupal_set_message($this->t('Saved the %label Workflow.', ['%label' => $workflow->label()]));
$this->messenger()->addStatus($this->t('Saved the %label Workflow.', ['%label' => $workflow->label()]));
}
/**
@@ -116,15 +116,13 @@ class WorkflowStateAddForm extends EntityForm {
* The current state of the form.
*/
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
if (!$form_state->isValidationComplete()) {
// Only do something once form validation is complete.
return;
}
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
$type_plugin = $entity->getTypePlugin();
// Replicate the validation that Workflow::addState() does internally as the
// form values have not been validated at this point.
if (!$type_plugin->hasState($values['id']) && !preg_match('/[^a-z0-9_]+/', $values['id'])) {
$type_plugin->addState($values['id'], $values['label']);
}
$entity->getTypePlugin()->addState($values['id'], $values['label']);
}
/**
@@ -162,7 +160,7 @@ class WorkflowStateAddForm extends EntityForm {
}
$workflow->save();
drupal_set_message($this->t('Created %label state.', [
$this->messenger()->addStatus($this->t('Created %label state.', [
'%label' => $workflow->getTypePlugin()->getState($form_state->getValue('id'))->label(),
]));
$form_state->setRedirectUrl($workflow->toUrl('edit-form'));
@@ -98,7 +98,7 @@ class WorkflowStateDeleteForm extends ConfirmFormBase {
->deleteState($this->stateId);
$this->workflow->save();
drupal_set_message($this->t(
$this->messenger()->addStatus($this->t(
'State %label deleted.',
['%label' => $workflow_label]
));
@@ -121,14 +121,14 @@ class WorkflowStateEditForm extends EntityForm {
'title' => $this->t('Edit'),
'url' => Url::fromRoute('entity.workflow.edit_transition_form', [
'workflow' => $workflow->id(),
'workflow_transition' => $transition->id()
'workflow_transition' => $transition->id(),
]),
];
$links['delete'] = [
'title' => t('Delete'),
'url' => Url::fromRoute('entity.workflow.delete_transition_form', [
'workflow' => $workflow->id(),
'workflow_transition' => $transition->id()
'workflow_transition' => $transition->id(),
]),
];
$form['transitions'][$transition->id()] = [
@@ -161,6 +161,10 @@ class WorkflowStateEditForm extends EntityForm {
* The current state of the form.
*/
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
if (!$form_state->isValidationComplete()) {
// Only do something once form validation is complete.
return;
}
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
$entity->getTypePlugin()->setStateLabel($values['id'], $values['label']);
@@ -201,7 +205,7 @@ class WorkflowStateEditForm extends EntityForm {
}
$workflow->save();
drupal_set_message($this->t('Saved %label state.', [
$this->messenger()->addStatus($this->t('Saved %label state.', [
'%label' => $workflow->getTypePlugin()->getState($this->stateId)->label(),
]));
$form_state->setRedirectUrl($workflow->toUrl('edit-form'));
@@ -226,8 +230,8 @@ class WorkflowStateEditForm extends EntityForm {
],
'#url' => Url::fromRoute('entity.workflow.delete_state_form', [
'workflow' => $this->entity->id(),
'workflow_state' => $this->stateId
])
'workflow_state' => $this->stateId,
]),
];
return $actions;
@@ -188,7 +188,7 @@ class WorkflowTransitionAddForm extends EntityForm {
}
$workflow->save();
drupal_set_message($this->t('Created %label transition.', [
$this->messenger()->addStatus($this->t('Created %label transition.', [
'%label' => $form_state->getValue('label'),
]));
$form_state->setRedirectUrl($workflow->toUrl('edit-form'));
@@ -98,7 +98,7 @@ class WorkflowTransitionDeleteForm extends ConfirmFormBase {
->deleteTransition($this->transition->id());
$this->workflow->save();
drupal_set_message($this->t('%transition transition deleted.', ['%transition' => $this->transition->label()]));
$this->messenger()->addStatus($this->t('%transition transition deleted.', ['%transition' => $this->transition->label()]));
$form_state->setRedirectUrl($this->getCancelUrl());
}
@@ -198,7 +198,7 @@ class WorkflowTransitionEditForm extends EntityForm {
}
$workflow->save();
drupal_set_message($this->t('Saved %label transition.', [
$this->messenger()->addStatus($this->t('Saved %label transition.', [
'%label' => $workflow->getTypePlugin()->getTransition($this->transitionId)->label(),
]));
$form_state->setRedirectUrl($workflow->toUrl('edit-form'));
@@ -224,8 +224,8 @@ class WorkflowTransitionEditForm extends EntityForm {
],
'#url' => Url::fromRoute('entity.workflow.delete_transition_form', [
'workflow' => $this->entity->id(),
'workflow_transition' => $this->transitionId
])
'workflow_transition' => $this->transitionId,
]),
];
return $actions;
@@ -152,7 +152,7 @@ abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterf
*/
public function getState($state_id) {
if (!isset($this->configuration['states'][$state_id])) {
throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.'");
throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.");
}
return new State(
$this,
@@ -167,7 +167,7 @@ abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterf
*/
public function setStateLabel($state_id, $label) {
if (!$this->hasState($state_id)) {
throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.'");
throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.");
}
$this->configuration['states'][$state_id]['label'] = $label;
return $this;
@@ -193,7 +193,7 @@ abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterf
*/
public function deleteState($state_id) {
if (!$this->hasState($state_id)) {
throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.'");
throw new \InvalidArgumentException("The state '$state_id' does not exist in workflow.");
}
if (count($this->configuration['states']) === 1) {
throw new \InvalidArgumentException("The state '$state_id' can not be deleted from workflow as it is the only state.");
@@ -226,14 +226,14 @@ abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterf
*/
public function addTransition($transition_id, $label, array $from_state_ids, $to_state_id) {
if ($this->hasTransition($transition_id)) {
throw new \InvalidArgumentException("The transition '$transition_id' already exists in workflow.'");
throw new \InvalidArgumentException("The transition '$transition_id' already exists in workflow.");
}
if (preg_match(static::VALID_ID_REGEX, $transition_id)) {
throw new \InvalidArgumentException("The transition ID '$transition_id' must contain only lowercase letters, numbers, and underscores.");
}
if (!$this->hasState($to_state_id)) {
throw new \InvalidArgumentException("The state '$to_state_id' does not exist in workflow.'");
throw new \InvalidArgumentException("The state '$to_state_id' does not exist in workflow.");
}
$this->configuration['transitions'][$transition_id] = [
'label' => $label,
@@ -311,7 +311,7 @@ abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterf
*/
public function getTransition($transition_id) {
if (!$this->hasTransition($transition_id)) {
throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow.'");
throw new \InvalidArgumentException("The transition '$transition_id' does not exist in workflow.");
}
return new Transition(
$this,
@@ -346,7 +346,7 @@ abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterf
public function getTransitionFromStateToState($from_state_id, $to_state_id) {
$transition_id = $this->getTransitionIdFromStateToState($from_state_id, $to_state_id);
if (empty($transition_id)) {
throw new \InvalidArgumentException("The transition from '$from_state_id' to '$to_state_id' does not exist in workflow.'");
throw new \InvalidArgumentException("The transition from '$from_state_id' to '$to_state_id' does not exist in workflow.");
}
return $this->getTransition($transition_id);
}
@@ -73,7 +73,7 @@ class WorkflowListBuilder extends ConfigEntityListBuilder {
$row['label'] = $entity->label();
$row['type']['data'] = [
'#markup' => $entity->getTypePlugin()->label()
'#markup' => $entity->getTypePlugin()->label(),
];
$items = array_map([State::class, 'labelCallback'], $entity->getTypePlugin()->getStates());
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- workflows
- drupal:workflows
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- workflows
- drupal:workflows
@@ -49,7 +49,7 @@ class WorkflowUiNoTypeTest extends BrowserTestBase {
$this->drupalGet('admin/config/workflow/workflows');
$this->assertSession()->pageTextNotContains('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
$this->assertSession()->linkExists('Add workflow');
$this->assertSession()->pageTextContains('There is no Workflow yet.');
$this->assertSession()->pageTextContains('There are no workflows yet.');
}
}
@@ -90,12 +90,19 @@ class WorkflowUiTest extends BrowserTestBase {
])->save();
$this->drupalLogin($this->createUser(['administer workflows']));
$this->drupalPostForm('admin/config/workflow/workflows/manage/test_workflow/add_state', [
'label' => 'Test State',
'id' => 'Invalid ID',
], 'Save');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
$this->drupalPostForm('admin/config/workflow/workflows/manage/test_workflow/add_transition', [
'label' => 'Test Transition',
'id' => 'Invalid ID',
], 'Save');
$this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
}
/**
@@ -109,7 +116,7 @@ class WorkflowUiTest extends BrowserTestBase {
$this->assertSession()->linkByHrefExists('admin/config/workflow/workflows');
$this->clickLink('Workflows');
$this->assertSession()->pageTextContains('Workflows');
$this->assertSession()->pageTextContains('There is no Workflow yet.');
$this->assertSession()->pageTextContains('There are no workflows yet.');
$this->clickLink('Add workflow');
$this->submitForm(['label' => 'Test', 'id' => 'test', 'workflow_type' => 'workflow_type_test'], 'Save');
$this->assertSession()->pageTextContains('Created the Test Workflow.');
@@ -253,7 +260,7 @@ class WorkflowUiTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('Are you sure you want to delete Test?');
$this->submitForm([], 'Delete');
$this->assertSession()->pageTextContains('Workflow Test deleted.');
$this->assertSession()->pageTextContains('There is no Workflow yet.');
$this->assertSession()->pageTextContains('There are no workflows yet.');
$this->assertNull($workflow_storage->loadUnchanged('test'), 'The test workflow has been deleted');
// Ensure that workflow types with default configuration are initialized
@@ -389,6 +396,21 @@ class WorkflowUiTest extends BrowserTestBase {
foreach ($elements as $key => $element) {
$this->assertEquals($expected_transitions[$key], $element->find('xpath', 'td')->getText());
}
// Ensure that there are enough weights to satisfy the potential number of
// states and transitions.
$this->assertSession()
->selectExists('states[three][weight]')
->selectOption('2');
$this->assertSession()
->selectExists('states[three][weight]')
->selectOption('-2');
$this->assertSession()
->selectExists('transitions[three][weight]')
->selectOption('2');
$this->assertSession()
->selectExists('transitions[three][weight]')
->selectOption('-2');
}
}
@@ -417,7 +417,6 @@ class WorkflowTest extends UnitTestCase {
$this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getTransitions([])));
}
/**
* @covers ::getTransition
*/
@@ -474,7 +473,6 @@ class WorkflowTest extends UnitTestCase {
$this->assertEquals(['archive'], array_keys($workflow->getTypePlugin()->getTransitionsForState('archived', 'to')));
}
/**
* @covers ::getTransitionFromStateToState
* @covers ::hasTransitionFromStateToState
@@ -3,4 +3,3 @@ entity.workflow.collection:
route_name: entity.workflow.collection
description: 'Configure workflows.'
parent: system.admin_config_workflow