switch workflow module to dev to fixe issue:

https://www.drupal.org/project/workflow/issues/2969569
This commit is contained in:
2018-09-12 15:46:28 +02:00
parent 03971cf56c
commit 4eee031fdd
34 changed files with 197 additions and 115 deletions
@@ -2,3 +2,6 @@
views.filter.workflow_state: views.filter.workflow_state:
type: views.filter.many_to_one type: views.filter.many_to_one
views.argument.workflow_state:
type: views.argument.string
@@ -6,8 +6,8 @@ package: Workflow
# core: 8.x # core: 8.x
type: module type: module
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -84,7 +84,7 @@ function workflow_access_user_role_insert(EntityInterface $entity) {
/** /**
* Implements hook_access_ENTITY_TYPE_update(). * Implements hook_access_ENTITY_TYPE_update().
* *
* @param EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
*/ */
function workflow_access_user_role_update(EntityInterface $entity) { function workflow_access_user_role_update(EntityInterface $entity) {
// Attend user to Rebuild data, because the weight of a role // Attend user to Rebuild data, because the weight of a role
@@ -6,8 +6,8 @@ package: Workflow
dependencies: dependencies:
- workflow - workflow
configure: workflow.cleanup.settings configure: workflow.cleanup.settings
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -7,8 +7,8 @@ type: module
dependencies: dependencies:
- workflow - workflow
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -5,8 +5,8 @@ type: module
# core: 8.x # core: 8.x
hidden: TRUE hidden: TRUE
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -47,7 +47,7 @@ class WorkflowAccessControlHandler extends \Drupal\workflow\WorkflowAccessContro
* - module.routing.yml * - module.routing.yml
* - hook_entity_operation * - hook_entity_operation
* *
* @param \Drupal\workflow_operations\WorkflowTransitionInterface|null $transition * @param \Drupal\workflow_operations\WorkflowTransitionInterface | null $transition
* *
* @return \Drupal\Core\Access\AccessResult * @return \Drupal\Core\Access\AccessResult
*/ */
@@ -23,10 +23,11 @@ class WorkflowPermissions extends \Drupal\workflow\WorkflowPermissions {
/** /**
* Returns a list of workflow permissions for a given workflow type. * Returns a list of workflow permissions for a given workflow type.
* *
* @param Workflow|\Drupal\workflow\Entity\Workflow $type * @param \Drupal\workflow\Entity\Workflow $type
* The workflow type. * The workflow type.
*
* @return array An associative array of permission names and descriptions. * @return array An associative array of permission names and descriptions.
* An associative array of permission names and descriptions. * An associative array of permission names and descriptions.
*/ */
protected function buildPermissions(Workflow $type) { protected function buildPermissions(Workflow $type) {
$type_id = $type->id(); $type_id = $type->id();
@@ -7,8 +7,8 @@ type: module
dependencies: dependencies:
- workflow - workflow
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -10,8 +10,8 @@ configure: entity.workflow_type.collection
dependencies: dependencies:
- workflow - workflow
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -32,7 +32,7 @@ class WorkflowHistoryAccess implements AccessInterface {
$uid = ($account) ? $account->id() : -1; $uid = ($account) ? $account->id() : -1;
$entity = workflow_url_get_entity(); $entity = workflow_url_get_entity(NULL, $routeMatch);
$entity_id = $entity->id(); $entity_id = $entity->id();
$entity_type = $entity->getEntityTypeId(); $entity_type = $entity->getEntityTypeId();
$entity_bundle = $entity->bundle(); $entity_bundle = $entity->bundle();
@@ -2,13 +2,11 @@
namespace Drupal\workflow\Controller; namespace Drupal\workflow\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\Controller\EntityListController; use Drupal\Core\Entity\Controller\EntityListController;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Render\RendererInterface; use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\workflow\Entity\WorkflowManager; use Drupal\workflow\Entity\WorkflowManager;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -60,10 +58,10 @@ class WorkflowTransitionListController extends EntityListController implements C
* Generates an overview table of older revisions of a node, * Generates an overview table of older revisions of a node,
* but only if WorkflowHistoryAccess::access() allows it. * but only if WorkflowHistoryAccess::access() allows it.
* *
* @param EntityInterface $node * @param \Drupal\Core\Entity\EntityInterface $node
* A node object. * A node object.
* @return array An array as expected by drupal_render(). * @return array An array as expected by drupal_render().
* An array as expected by drupal_render(). * An array as expected by drupal_render().
*/ */
public function historyOverview(EntityInterface $node = NULL) { public function historyOverview(EntityInterface $node = NULL) {
$form = []; $form = [];
@@ -96,14 +94,14 @@ class WorkflowTransitionListController extends EntityListController implements C
* Step 1: generate the Transition Form. * Step 1: generate the Transition Form.
*/ */
// Add the WorkflowTransitionForm to the page. // Add the WorkflowTransitionForm to the page.
$form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name); $form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name, []);
/* /*
* Step 2: generate the Transition History List. * Step 2: generate the Transition History List.
*/ */
$view = NULL; $view = NULL;
$moduleHandler = \Drupal::service('module_handler'); $moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('views')){ if ($moduleHandler->moduleExists('views')) {
$view = Views::getView('workflow_entity_history'); $view = Views::getView('workflow_entity_history');
} }
if (is_object($view) && $view->storage->status()) { if (is_object($view) && $view->storage->status()) {
@@ -119,7 +117,6 @@ class WorkflowTransitionListController extends EntityListController implements C
// @deprecated. Use the Views display above. // @deprecated. Use the Views display above.
// Add the history list from programmed WorkflowTransitionListController. // Add the history list from programmed WorkflowTransitionListController.
$entity_type = 'workflow_transition'; $entity_type = 'workflow_transition';
// $form = $this->listing('workflow_transition');
$list_builder = $this->entityTypeManager()->getListBuilder($entity_type); $list_builder = $this->entityTypeManager()->getListBuilder($entity_type);
// Add the Node explicitly, since $list_builder expects a Transition. // Add the Node explicitly, since $list_builder expects a Transition.
$list_builder->workflow_entity = $entity; $list_builder->workflow_entity = $entity;
@@ -130,7 +127,6 @@ class WorkflowTransitionListController extends EntityListController implements C
/* /*
* Finally: sort the elements (overriding their weight). * Finally: sort the elements (overriding their weight).
*/ */
// $form['#weight'] = 10;
$form['actions']['#weight'] = 100; $form['actions']['#weight'] = 100;
$form['table']['#weight'] = 201; $form['table']['#weight'] = 201;
@@ -24,33 +24,13 @@ use Drupal\workflow\Entity\WorkflowTransitionInterface;
*/ */
class WorkflowTransitionElement extends FormElement { class WorkflowTransitionElement extends FormElement {
/**
* Form element validation handler.
*
* Note that #maxlength is validated by _form_validate() already.
*
* This checks that the submitted value:
* - Does not contain the replacement character only.
* - Does not contain disallowed characters.
* - Is unique; i.e., does not already exist.
* - Does not exceed the maximum length (via #maxlength).
* - Cannot be changed after creation (via #disabled).
*
* @param array $element Reference to the Form element
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param array $complete_form
*/
public static function validateTransition(&$element, FormStateInterface $form_state, &$complete_form) {
workflow_debug(__FILE__, __FUNCTION__, __LINE__); // @todo D8-port: still test this snippet.
}
/** /**
* Generate an element. * Generate an element.
* *
* This function is referenced in the Annotation for this class. * This function is referenced in the Annotation for this class.
* *
* @param $element * @param $element
* @param FormStateInterface $form_state * @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $complete_form * @param $complete_form
* *
* @return array * @return array
@@ -73,7 +53,7 @@ class WorkflowTransitionElement extends FormElement {
* @example $element += WorkflowTransitionElement::transitionElement($element, $form_state, $form); * @example $element += WorkflowTransitionElement::transitionElement($element, $form_state, $form);
* *
* @param array $element Reference to the form element * @param array $element Reference to the form element
* @param FormStateInterface $form_state * @param \Drupal\Core\Form\FormStateInterface $form_state
* @param array $complete_form * @param array $complete_form
* *
* @return array * @return array
@@ -431,7 +411,7 @@ class WorkflowTransitionElement extends FormElement {
* *
* @param \Drupal\Core\Entity\EntityInterface $transition * @param \Drupal\Core\Entity\EntityInterface $transition
* @param array $form * @param array $form
* @param FormStateInterface $form_state * @param \Drupal\Core\Form\FormStateInterface $form_state
* @param array $item * @param array $item
* *
* @return WorkflowTransitionInterface * @return WorkflowTransitionInterface
@@ -540,7 +520,7 @@ class WorkflowTransitionElement extends FormElement {
// but only with a hack on a widget. // but only with a hack on a widget.
// @todo: Attached fields are not supported in ScheduledTransitions. // @todo: Attached fields are not supported in ScheduledTransitions.
$fields = WorkflowManager::getAttachedFields('workflow_transition', $transition->bundle()); $fields = WorkflowManager::getAttachedFields('workflow_transition', $transition->bundle());
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $nodeField */ /** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */
foreach ($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
$user_input = isset($form_state->getUserInput()[$field_name]) ? $form_state->getUserInput()[$field_name] : []; $user_input = isset($form_state->getUserInput()[$field_name]) ? $form_state->getUserInput()[$field_name] : [];
if (isset($item[$field_name])) { if (isset($item[$field_name])) {
@@ -6,6 +6,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\workflow\WorkflowURLRouteParametersTrait;
/** /**
* Workflow configuration entity to persistently store configuration. * Workflow configuration entity to persistently store configuration.
@@ -55,6 +56,11 @@ use Drupal\Core\Session\AccountInterface;
*/ */
class Workflow extends ConfigEntityBase implements WorkflowInterface { class Workflow extends ConfigEntityBase implements WorkflowInterface {
/*
* Provide URL route parameters for entity links.
*/
use WorkflowURLRouteParametersTrait;
/** /**
* The machine name. * The machine name.
* *
@@ -91,6 +97,13 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
*/ */
protected $module = 'workflow'; protected $module = 'workflow';
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
parent::calculateDependencies();
}
/** /**
* CRUD functions. * CRUD functions.
*/ */
@@ -142,7 +155,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
*/ */
public function delete() { public function delete() {
if (!$this->isDeletable()) { if (!$this->isDeletable()) {
$message = t('Workflow %workflow is not Deletable. Please delete the field where this workflow type is reffered', $message = t('Workflow %workflow is not Deletable. Please delete the field where this workflow type is referred',
['%workflow' => $this->label()]); ['%workflow' => $this->label()]);
drupal_set_message($message, 'error'); drupal_set_message($message, 'error');
return; return;
@@ -6,6 +6,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\user\UserInterface; use Drupal\user\UserInterface;
use Drupal\workflow\WorkflowTypeAttributeTrait; use Drupal\workflow\WorkflowTypeAttributeTrait;
use Drupal\workflow\WorkflowURLRouteParametersTrait;
/** /**
* Workflow configuration entity to persistently store configuration. * Workflow configuration entity to persistently store configuration.
@@ -50,6 +51,10 @@ class WorkflowConfigTransition extends ConfigEntityBase implements WorkflowConfi
* Add variables and get/set methods for Workflow property. * Add variables and get/set methods for Workflow property.
*/ */
use WorkflowTypeAttributeTrait; use WorkflowTypeAttributeTrait;
/*
* Provide URL route parameters for entity links.
*/
use WorkflowURLRouteParametersTrait;
// Transition data. // Transition data.
public $id; public $id;
@@ -86,12 +91,23 @@ class WorkflowConfigTransition extends ConfigEntityBase implements WorkflowConfi
* @param $to_sid * @param $to_sid
*/ */
public function setValues($from_sid, $to_sid) { public function setValues($from_sid, $to_sid) {
// @todo : unused parameters. Remove the method/parameters?
$state = WorkflowState::load($this->to_sid ? $this->to_sid : $this->from_sid); $state = WorkflowState::load($this->to_sid ? $this->to_sid : $this->from_sid);
if($state) { if($state) {
$this->setWorkflow($state->getWorkflow()); $this->setWorkflow($state->getWorkflow());
} }
} }
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
parent::calculateDependencies();
$this->addDependency('config', $this->getFromState()->getConfigDependencyName());
$this->addDependency('config', $this->getToState()->getConfigDependencyName());
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@@ -50,6 +50,7 @@ interface WorkflowInterface {
* saved directly in the database. This is because you can use States only * saved directly in the database. This is because you can use States only
* with Transitions, and they rely on State IDs which are generated * with Transitions, and they rely on State IDs which are generated
* magically when saving the State. But you may need a temporary state. * magically when saving the State. But you may need a temporary state.
*
* @return \Drupal\workflow\Entity\WorkflowState * @return \Drupal\workflow\Entity\WorkflowState
* The new state. * The new state.
*/ */
@@ -71,10 +72,10 @@ interface WorkflowInterface {
* Uses WorkflowState::getOptions(), because this does an access check. * Uses WorkflowState::getOptions(), because this does an access check.
* The first State ID is user-dependent! * The first State ID is user-dependent!
* *
* @param EntityInterface|null $entity * @param \Drupal\Core\Entity\EntityInterface | null $entity
* The entity at hand. May be NULL (E.g., on a Field settings page). * The entity at hand. May be NULL (E.g., on a Field settings page).
* @param $field_name * @param $field_name
* @param AccountInterface $user * @param \Drupal\Core\Session\AccountInterface $user
* @param bool $force * @param bool $force
* *
* @return string * @return string
@@ -86,10 +87,10 @@ interface WorkflowInterface {
* Returns the next state for the current state. * Returns the next state for the current state.
* Is used in VBO Bulk actions. * Is used in VBO Bulk actions.
* *
* @param EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity at hand. * The entity at hand.
* @param $field_name * @param $field_name
* @param AccountInterface $user * @param \Drupal\Core\Session\AccountInterface $user
* @param bool $force * @param bool $force
* *
* @return string * @return string
@@ -162,7 +163,7 @@ interface WorkflowInterface {
* @param string $from_sid * @param string $from_sid
* @param string $to_sid * @param string $to_sid
* *
* @return WorkflowConfigTransition[] * @return \Drupal\workflow\Entity\WorkflowConfigTransition[]
*/ */
public function getTransitionsByStateId($from_sid, $to_sid); public function getTransitionsByStateId($from_sid, $to_sid);
@@ -7,12 +7,12 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/** /**
* Manages entity type plugin definitions. * Manages entity type plugin definitions.
@@ -27,13 +27,6 @@ class WorkflowManager implements WorkflowManagerInterface {
*/ */
protected $entityTypeManager; protected $entityTypeManager;
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/** /**
* The user settings config object. * The user settings config object.
* *
@@ -61,20 +54,17 @@ class WorkflowManager implements WorkflowManagerInterface {
* *
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity_type manager service. * The entity_type manager service.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory. * The config factory.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service. * The string translation service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service. * The module handler service.
* @param \Drupal\Core\Session\AccountInterface $current_user * @param \Drupal\Core\Session\AccountInterface $current_user
* The current user. * The current user.
*/ */
public function __construct(EntityTypeManagerInterface $entity_type_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user) { public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
$this->entityTypeManager = $entity_type_manager; $this->entityTypeManager = $entity_type_manager;
$this->queryFactory = $query_factory;
$this->userConfig = $config_factory->get('user.settings'); $this->userConfig = $config_factory->get('user.settings');
$this->stringTranslation = $string_translation; $this->stringTranslation = $string_translation;
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
@@ -165,6 +155,7 @@ class WorkflowManager implements WorkflowManagerInterface {
$comment = ''; $comment = '';
$old_sid = WorkflowManager::getPreviousStateId($entity, $field_name); $old_sid = WorkflowManager::getPreviousStateId($entity, $field_name);
$new_sid = $entity->$field_name->value; $new_sid = $entity->$field_name->value;
$field_info = FieldStorageConfig::loadByName($entity->getEntityTypeId(), $field_name);
if ((!$new_sid) && $wid = $field_info->getSetting('workflow_type')) { if ((!$new_sid) && $wid = $field_info->getSetting('workflow_type')) {
/** @var Workflow $workflow */ /** @var Workflow $workflow */
$workflow = Workflow::load($wid); $workflow = Workflow::load($wid);
@@ -309,12 +300,12 @@ class WorkflowManager implements WorkflowManagerInterface {
*/ */
$uid = $account->id(); $uid = $account->id();
$new_uid = 0; $new_uid = 0;
$database = \Drupal::database();
db_update('workflow_transition_history') $database->update('workflow_transition_history')
->fields(['uid' => $new_uid]) ->fields(['uid' => $new_uid])
->condition('uid', $uid, '=') ->condition('uid', $uid, '=')
->execute(); ->execute();
db_update('workflow_transition_schedule') $database->update('workflow_transition_schedule')
->fields(['uid' => $new_uid]) ->fields(['uid' => $new_uid])
->condition('uid', $uid, '=') ->condition('uid', $uid, '=')
->execute(); ->execute();
@@ -405,7 +396,7 @@ class WorkflowManager implements WorkflowManagerInterface {
// Entity is new or in preview or there is no current state. Use previous state. // Entity is new or in preview or there is no current state. Use previous state.
// (E.g., content was created before adding workflow.) // (E.g., content was created before adding workflow.)
if ( !$sid || !empty($entity->isNew()) || !empty($entity->in_preview) ) { if (!$sid || !empty($entity->isNew()) || !empty($entity->in_preview)) {
$sid = self::getPreviousStateId($entity, $field_name); $sid = self::getPreviousStateId($entity, $field_name);
} }
@@ -105,7 +105,7 @@ interface WorkflowManagerInterface {
* Gets the TransitionWidget in a form (for e.g., Workflow History Tab) * Gets the TransitionWidget in a form (for e.g., Workflow History Tab)
* @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* @param string $field_name * @param string $field_name
* * @param array $form_state_additions
* @return * @return
*/ */
public static function getWorkflowTransitionForm(EntityInterface $entity, $field_name, array $form_state_additions = []); public static function getWorkflowTransitionForm(EntityInterface $entity, $field_name, array $form_state_additions = []);
@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\workflow\WorkflowTypeAttributeTrait; use Drupal\workflow\WorkflowTypeAttributeTrait;
use Drupal\workflow\WorkflowURLRouteParametersTrait;
/** /**
* Workflow configuration entity to persistently store configuration. * Workflow configuration entity to persistently store configuration.
@@ -59,6 +60,10 @@ class WorkflowState extends ConfigEntityBase {
* Add variables and get/set methods for Workflow property. * Add variables and get/set methods for Workflow property.
*/ */
use WorkflowTypeAttributeTrait; use WorkflowTypeAttributeTrait;
/*
* Provide URL route parameters for entity links.
*/
use WorkflowURLRouteParametersTrait;
/** /**
* The machine name. * The machine name.
@@ -125,6 +130,19 @@ class WorkflowState extends ConfigEntityBase {
parent::__construct($values, $entityType); parent::__construct($values, $entityType);
} }
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
parent::calculateDependencies();
// We cannot use $this->getWorkflow()->getConfigDependencyName() because
// calling $this->getWorkflow() here causes an infinite loop.
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $workflow_type */
$workflow_type = \Drupal::entityTypeManager()->getDefinition('workflow_type');
$this->addDependency('config', $workflow_type->getConfigPrefix() . '.' . $this->getWorkflowId());
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@@ -179,7 +197,7 @@ class WorkflowState extends ConfigEntityBase {
$states = parent::loadMultiple(); $states = parent::loadMultiple();
usort($states, ['Drupal\workflow\Entity\WorkflowState', 'sort'] ); usort($states, ['Drupal\workflow\Entity\WorkflowState', 'sort'] );
// Filter onl Wid, if requested, E.g., by Workflow->getStates(). // Filter on Wid, if requested, E.g., by Workflow->getStates().
// Set the ID as array key. // Set the ID as array key.
$result = []; $result = [];
foreach ($states as $state) { foreach ($states as $state) {
@@ -56,7 +56,8 @@ abstract class WorkflowStateActionBase extends ConfigurableActionBase implements
} }
/** /**
* @param EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
*
* @return \Drupal\workflow\Entity\WorkflowTransitionInterface * @return \Drupal\workflow\Entity\WorkflowTransitionInterface
*/ */
protected function getTransitionForExecution(EntityInterface $entity) { protected function getTransitionForExecution(EntityInterface $entity) {
@@ -67,7 +67,7 @@ class WorkflowTransitionBlock extends BlockBase {
* Output: generate the Transition Form. * Output: generate the Transition Form.
*/ */
// Add the WorkflowTransitionForm to the page. // Add the WorkflowTransitionForm to the page.
$form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name); $form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name, []);
return $form; return $form;
} }
@@ -175,7 +175,7 @@ class WorkflowDefaultFormatter extends FormatterBase implements ContainerFactory
// BEGIN Copy from CommentDefaultFormatter // BEGIN Copy from CommentDefaultFormatter
$elements['#cache']['contexts'][] = 'user.permissions'; $elements['#cache']['contexts'][] = 'user.permissions';
// Add the WorkflowTransitionForm to the page. // Add the WorkflowTransitionForm to the page.
$output['workflows'] = WorkflowManager::getWorkflowTransitionForm($entity, $field_name); $output['workflows'] = WorkflowManager::getWorkflowTransitionForm($entity, $field_name, []);
// Only show the add workflow form if the user has permission. // Only show the add workflow form if the user has permission.
$elements['#cache']['contexts'][] = 'user.roles'; $elements['#cache']['contexts'][] = 'user.roles';
@@ -270,7 +270,7 @@ class WorkflowItem extends ListItemBase {
* *
* This string format is suitable for edition in a textarea. * This string format is suitable for edition in a textarea.
* *
* @param WorkflowState[] $states * @param \Drupal\Core\Entity\EntityInterface[] $states
* An array of WorkflowStates, where array keys are values and array values are * An array of WorkflowStates, where array keys are values and array values are
* labels. * labels.
* *
@@ -95,7 +95,13 @@ class WorkflowDefaultWidget extends WidgetBase {
$element['#default_value'] = $transition; $element['#default_value'] = $transition;
$element += WorkflowTransitionElement::transitionElement($element, $form_state, $form); $element += WorkflowTransitionElement::transitionElement($element, $form_state, $form);
// Step 2: use the Form, in order to get extra fields. // Step 2: use the Form, in order to get extra fields.
$workflow_form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name); $form_state_additions = [
'input' => $form_state->getUserInput(),
'values' => $form_state->getValues(),
'triggering_element' => $form_state->getTriggeringElement(),
];
$workflow_form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name, $form_state_additions);
// Determine and add the attached fields. // Determine and add the attached fields.
$attached_fields = WorkflowManager::getAttachedFields('workflow_transition', $wid); $attached_fields = WorkflowManager::getAttachedFields('workflow_transition', $wid);
foreach ($attached_fields as $key => $attached_field) { foreach ($attached_fields as $key => $attached_field) {
@@ -64,7 +64,7 @@ class WorkflowFieldConstraintValidator extends ConstraintValidator implements Co
} }
/** /**
* @param FieldStorageConfig $field_storage * @param \Drupal\field\Entity\FieldStorageConfig $field_storage
* *
* @return bool * @return bool
*/ */
@@ -0,0 +1,23 @@
<?php
namespace Drupal\workflow\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\StringArgument;
/**
* Argument handler to accept a Workflow State.
*
* @ViewsArgument("workflow_state")
*/
class WorkflowState extends StringArgument {
/**
* Override the behavior of title().
*
* Get the user friendly version of the workflow state.
*/
public function title() {
return workflow_get_sid_name($this->argument);
}
}
@@ -41,17 +41,16 @@ class RouteSubscriber extends RouteSubscriberBase {
foreach ($field_list as $entityTypeId => $fields) { foreach ($field_list as $entityTypeId => $fields) {
/* /*
* @todo Create a Entity workflow field list page and a route * @todo: For entities with +1 workflow fields, Create an
* that redirect to the page when a entity have more than * Entity workflow field list page and a route
* one workflow fields. * that redirect to the correct page.
* @todo: Routes for 3 workflow fields on 3 different bundles of 1 entity type.
*/ */
// Only 1 field. Workflow is redirect to workflow/{field_name}. // Generate route for default field. Redirect to workflow/{field_name}.
if (count($fields) < 2) { $path = "/$entityTypeId/{{$entityTypeId}}/workflow";
$path = "/$entityTypeId/{{$entityTypeId}}/workflow"; $route = $this->getEntityLoadRoute($entityTypeId, $path);
$route = $this->getEntityLoadRoute($entityTypeId, $path); $collection->add("entity.$entityTypeId.workflow_history", $route);
$collection->add("entity.$entityTypeId.workflow_history", $route);
}
// Generate one route for each workflow field. // Generate one route for each workflow field.
foreach ($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
@@ -27,14 +27,14 @@ trait WorkflowTypeAttributeTrait {
* It must explicitly be defined, and not be public, to avoid errors * It must explicitly be defined, and not be public, to avoid errors
* when exporting with json_encode(). * when exporting with json_encode().
* *
* @var Workflow * @var \Drupal\workflow\Entity\Workflow
*/ */
protected $workflow = NULL; protected $workflow = NULL;
/** /**
* @param Workflow $workflow * @param \Drupal\workflow\Entity\Workflow $workflow
*/ */
public function setWorkflow(Workflow $workflow) { public function setWorkflow(Workflow $workflow = NULL) {
$this->wid = ''; $this->wid = '';
$this->workflow = NULL; $this->workflow = NULL;
if ($workflow) { if ($workflow) {
@@ -64,6 +64,8 @@ trait WorkflowTypeAttributeTrait {
/** /**
* Sets the Workflow ID of this object. * Sets the Workflow ID of this object.
* *
* @param $wid Workflow ID
*
* @return object * @return object
*/ */
public function setWorkflowId($wid) { public function setWorkflowId($wid) {
@@ -0,0 +1,19 @@
<?php
namespace Drupal\workflow;
/**
* Provides route parameters for workflow entity types.
*/
trait WorkflowURLRouteParametersTrait {
/**
* {@inheritdoc}
*/
protected function urlRouteParameters($rel) {
$uri_route_parameters = parent::urlRouteParameters($rel);
$uri_route_parameters['workflow_type'] = $this->getWorkflowId();
return $uri_route_parameters;
}
}
@@ -25,7 +25,7 @@ use Drupal\workflow\Entity\WorkflowTransitionInterface;
* 'operations': Allow modules to insert their own workflow operations. * 'operations': Allow modules to insert their own workflow operations.
* 'workflow': Allow modules to insert workflow operations. * 'workflow': Allow modules to insert workflow operations.
* 'state': Allow modules to insert state operations. * 'state': Allow modules to insert state operations.
* @param EntityInterface|null $entity * @param \Drupal\Core\Entity\EntityInterface|null $entity
* The current workflow/state/transition object. * The current workflow/state/transition object.
* *
* @return array * @return array
@@ -87,9 +87,9 @@ function hook_workflow_operations($op, EntityInterface $entity = NULL) {
* @param string $op * @param string $op
* The current workflow operation. * The current workflow operation.
* E.g., 'transition pre', 'transition post'. * E.g., 'transition pre', 'transition post'.
* @param WorkflowTransitionInterface $transition * @param \Drupal\workflow\Entity\WorkflowTransitionInterface $transition
* The transition, that contains all of the above. * The transition, that contains all of the above.
* @param UserInterface $user * @param \Drupal\user\UserInterface $user
* *
* @return bool|void * @return bool|void
*/ */
@@ -10,8 +10,8 @@ dependencies:
- options - options
- user - user
# Information added by Drupal.org packaging script on 2018-04-29 # Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1' version: '8.x-1.1+18-dev'
core: '8.x' core: '8.x'
project: 'workflow' project: 'workflow'
datestamp: 1525039388 datestamp: 1536080308
@@ -526,7 +526,7 @@ function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle
else { else {
// The field is a base/extra field not a configurable Field via Field UI. // The field is a base/extra field not a configurable Field via Field UI.
// Refetch the field definitions, with extra data. // Re-fetch the field definitions, with extra data.
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($e_type, $entity_bundle); $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($e_type, $entity_bundle);
// @todo ?? Loop over bundles? // @todo ?? Loop over bundles?
/** @var \Drupal\Core\Field\BaseFieldDefinition $field_config */ /** @var \Drupal\Core\Field\BaseFieldDefinition $field_config */
@@ -552,16 +552,21 @@ function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle
* This is a hack. It should be solved by using $route_match. * This is a hack. It should be solved by using $route_match.
* *
* @param \Drupal\Core\Entity\EntityInterface|null $entity * @param \Drupal\Core\Entity\EntityInterface|null $entity
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* *
* @return \Drupal\Core\Entity\EntityInterface * @return \Drupal\Core\Entity\EntityInterface
*/ */
function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = NULL) { function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = NULL, \Drupal\Core\Routing\RouteMatchInterface $route_match = NULL) {
if ($entity) { if ($entity) {
return $entity; return $entity;
} }
if (!$route_match) {
$route_match = \Drupal::routeMatch();
}
$entities = []; $entities = [];
foreach (\Drupal::routeMatch()->getParameters() as $param) { foreach ($route_match->getParameters() as $param) {
if ($param instanceof \Drupal\Core\Entity\EntityInterface) { if ($param instanceof \Drupal\Core\Entity\EntityInterface) {
$entities[] = $param; $entities[] = $param;
} }
@@ -576,8 +581,8 @@ function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = N
// On workflow tab, we'd get an id. // On workflow tab, we'd get an id.
// This is an indicator that the route is mal-configured. // This is an indicator that the route is mal-configured.
workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'route declaration is not optimal.'); workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'route declaration is not optimal.');
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value); // return $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value);
return $entity; return NULL;
} }
return $value; return $value;
@@ -1,7 +1,7 @@
services: services:
workflow.manager: workflow.manager:
class: Drupal\workflow\Entity\WorkflowManager class: Drupal\workflow\Entity\WorkflowManager
arguments: ['@entity_type.manager', '@entity.query', '@config.factory', '@string_translation', '@module_handler', '@current_user'] arguments: ['@entity_type.manager', '@config.factory', '@string_translation', '@module_handler', '@current_user']
workflow.route_subscriber: workflow.route_subscriber:
class: Drupal\workflow\Routing\RouteSubscriber class: Drupal\workflow\Routing\RouteSubscriber
@@ -7,6 +7,8 @@
* @ingroup views_module_handlers * @ingroup views_module_handlers
*/ */
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\workflow\Entity\WorkflowManager;
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
/** /**
@@ -18,10 +20,16 @@ function workflow_field_views_data(FieldStorageConfigInterface $field) {
foreach ($data as $table_name => $table_data) { foreach ($data as $table_name => $table_data) {
foreach ($table_data as $field_name => $field_data) { foreach ($table_data as $field_name => $field_data) {
if (isset($field_data['filter']) && $field_name != 'delta') { if ($field_name == 'delta') {
continue;
}
if (isset($field_data['filter'])) {
$data[$table_name][$field_name]['filter']['wid'] = (array_key_exists('workflow_type', $settings)) ? $settings['workflow_type'] : ''; $data[$table_name][$field_name]['filter']['wid'] = (array_key_exists('workflow_type', $settings)) ? $settings['workflow_type'] : '';
$data[$table_name][$field_name]['filter']['id'] = 'workflow_state'; $data[$table_name][$field_name]['filter']['id'] = 'workflow_state';
} }
if (isset($field_data['argument'])) {
$data[$table_name][$field_name]['argument']['id'] = 'workflow_state';
}
} }
} }
@@ -33,12 +41,12 @@ function workflow_field_views_data(FieldStorageConfigInterface $field) {
*/ */
function workflow_views_data_alter(array &$data) { function workflow_views_data_alter(array &$data) {
// Provide an integration for each entity type except workflow entities. // Provide an integration for each entity type except workflow entities.
// copied from comment.views.inc // Copied from comment.views.inc.
foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) { foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) {
if (\Drupal\workflow\Entity\WorkflowManager::isWorkflowEntityType($entity_type_id)) { if (WorkflowManager::isWorkflowEntityType($entity_type_id)) {
continue; continue;
} }
if (!$entity_type->entityClassImplements(\Drupal\Core\Entity\ContentEntityInterface::class)) { if (!$entity_type->entityClassImplements(ContentEntityInterface::class)) {
continue; continue;
} }
if (!$entity_type->getBaseTable()) { if (!$entity_type->getBaseTable()) {