Преглед изворни кода

switch workflow module to dev to fixe issue:
https://www.drupal.org/project/workflow/issues/2969569

Bachir Soussi Chiadmi пре 6 година
родитељ
комит
4eee031fdd
34 измењених фајлова са 197 додато и 115 уклоњено
  1. 3 0
      sites/all/modules/contrib/admin/workflow/config/schema/workflow.views.schema.yml
  2. 3 3
      sites/all/modules/contrib/admin/workflow/modules/workflow_access/workflow_access.info.yml
  3. 1 1
      sites/all/modules/contrib/admin/workflow/modules/workflow_access/workflow_access.module
  4. 3 3
      sites/all/modules/contrib/admin/workflow/modules/workflow_cleanup/workflow_cleanup.info.yml
  5. 3 3
      sites/all/modules/contrib/admin/workflow/modules/workflow_devel/workflow_devel.info.yml
  6. 3 3
      sites/all/modules/contrib/admin/workflow/modules/workflow_field/workflowfield.info.yml
  7. 1 1
      sites/all/modules/contrib/admin/workflow/modules/workflow_operations/src/WorkflowAccessControlHandler.php
  8. 3 2
      sites/all/modules/contrib/admin/workflow/modules/workflow_operations/src/WorkflowPermissions.php
  9. 3 3
      sites/all/modules/contrib/admin/workflow/modules/workflow_operations/workflow_operations.info.yml
  10. 3 3
      sites/all/modules/contrib/admin/workflow/modules/workflow_ui/workflow_ui.info.yml
  11. 1 1
      sites/all/modules/contrib/admin/workflow/src/Access/WorkflowHistoryAccess.php
  12. 4 8
      sites/all/modules/contrib/admin/workflow/src/Controller/WorkflowTransitionListController.php
  13. 4 24
      sites/all/modules/contrib/admin/workflow/src/Element/WorkflowTransitionElement.php
  14. 14 1
      sites/all/modules/contrib/admin/workflow/src/Entity/Workflow.php
  15. 16 0
      sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowConfigTransition.php
  16. 6 5
      sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowInterface.php
  17. 8 17
      sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowManager.php
  18. 1 1
      sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowManagerInterface.php
  19. 19 1
      sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowState.php
  20. 2 1
      sites/all/modules/contrib/admin/workflow/src/Plugin/Action/WorkflowStateActionBase.php
  21. 1 1
      sites/all/modules/contrib/admin/workflow/src/Plugin/Block/WorkflowTransitionBlock.php
  22. 1 1
      sites/all/modules/contrib/admin/workflow/src/Plugin/Field/FieldFormatter/WorkflowDefaultFormatter.php
  23. 1 1
      sites/all/modules/contrib/admin/workflow/src/Plugin/Field/FieldType/WorkflowItem.php
  24. 7 1
      sites/all/modules/contrib/admin/workflow/src/Plugin/Field/FieldWidget/WorkflowDefaultWidget.php
  25. 1 1
      sites/all/modules/contrib/admin/workflow/src/Plugin/Validation/Constraint/WorkflowFieldConstraintValidator.php
  26. 23 0
      sites/all/modules/contrib/admin/workflow/src/Plugin/views/argument/WorkflowState.php
  27. 9 10
      sites/all/modules/contrib/admin/workflow/src/Routing/RouteSubscriber.php
  28. 5 3
      sites/all/modules/contrib/admin/workflow/src/WorkflowTypeAttributeTrait.php
  29. 19 0
      sites/all/modules/contrib/admin/workflow/src/WorkflowURLRouteParametersTrait.php
  30. 3 3
      sites/all/modules/contrib/admin/workflow/workflow.api.php
  31. 3 3
      sites/all/modules/contrib/admin/workflow/workflow.info.yml
  32. 10 5
      sites/all/modules/contrib/admin/workflow/workflow.module
  33. 1 1
      sites/all/modules/contrib/admin/workflow/workflow.services.yml
  34. 12 4
      sites/all/modules/contrib/admin/workflow/workflow.views.inc

+ 3 - 0
sites/all/modules/contrib/admin/workflow/config/schema/workflow.views.schema.yml

@@ -2,3 +2,6 @@
 
 views.filter.workflow_state:
   type: views.filter.many_to_one
+
+views.argument.workflow_state:
+  type: views.argument.string

+ 3 - 3
sites/all/modules/contrib/admin/workflow/modules/workflow_access/workflow_access.info.yml

@@ -6,8 +6,8 @@ package: Workflow
 # core: 8.x
 type: module
 
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 1 - 1
sites/all/modules/contrib/admin/workflow/modules/workflow_access/workflow_access.module

@@ -84,7 +84,7 @@ function workflow_access_user_role_insert(EntityInterface $entity) {
 /**
  * Implements hook_access_ENTITY_TYPE_update().
  *
- * @param EntityInterface $entity
+ * @param \Drupal\Core\Entity\EntityInterface $entity
  */
 function workflow_access_user_role_update(EntityInterface $entity) {
   // Attend user to Rebuild data, because the weight of a role

+ 3 - 3
sites/all/modules/contrib/admin/workflow/modules/workflow_cleanup/workflow_cleanup.info.yml

@@ -6,8 +6,8 @@ package: Workflow
 dependencies:
   - workflow
 configure: workflow.cleanup.settings
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 3 - 3
sites/all/modules/contrib/admin/workflow/modules/workflow_devel/workflow_devel.info.yml

@@ -7,8 +7,8 @@ type: module
 dependencies:
   - workflow
 
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 3 - 3
sites/all/modules/contrib/admin/workflow/modules/workflow_field/workflowfield.info.yml

@@ -5,8 +5,8 @@ type: module
 # core: 8.x
 
 hidden: TRUE
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 1 - 1
sites/all/modules/contrib/admin/workflow/modules/workflow_operations/src/WorkflowAccessControlHandler.php

@@ -47,7 +47,7 @@ class WorkflowAccessControlHandler extends \Drupal\workflow\WorkflowAccessContro
    * - module.routing.yml
    * - hook_entity_operation
    *
-   * @param \Drupal\workflow_operations\WorkflowTransitionInterface|null $transition
+   * @param \Drupal\workflow_operations\WorkflowTransitionInterface | null $transition
    *
    * @return \Drupal\Core\Access\AccessResult
    */

+ 3 - 2
sites/all/modules/contrib/admin/workflow/modules/workflow_operations/src/WorkflowPermissions.php

@@ -23,10 +23,11 @@ class WorkflowPermissions extends \Drupal\workflow\WorkflowPermissions {
   /**
    * 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.
+   *
    * @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) {
     $type_id = $type->id();

+ 3 - 3
sites/all/modules/contrib/admin/workflow/modules/workflow_operations/workflow_operations.info.yml

@@ -7,8 +7,8 @@ type: module
 dependencies:
   - workflow
 
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 3 - 3
sites/all/modules/contrib/admin/workflow/modules/workflow_ui/workflow_ui.info.yml

@@ -10,8 +10,8 @@ configure: entity.workflow_type.collection
 dependencies:
   - workflow
 
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 1 - 1
sites/all/modules/contrib/admin/workflow/src/Access/WorkflowHistoryAccess.php

@@ -32,7 +32,7 @@ class WorkflowHistoryAccess implements AccessInterface {
 
     $uid = ($account) ? $account->id() : -1;
 
-    $entity = workflow_url_get_entity();
+    $entity = workflow_url_get_entity(NULL, $routeMatch);
     $entity_id = $entity->id();
     $entity_type = $entity->getEntityTypeId();
     $entity_bundle = $entity->bundle();

+ 4 - 8
sites/all/modules/contrib/admin/workflow/src/Controller/WorkflowTransitionListController.php

@@ -2,13 +2,11 @@
 
 namespace Drupal\workflow\Controller;
 
-use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Datetime\DateFormatter;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Drupal\Core\Entity\Controller\EntityListController;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Render\RendererInterface;
-use Drupal\Core\Session\AccountInterface;
 use Drupal\views\Views;
 use Drupal\workflow\Entity\WorkflowManager;
 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,
    * but only if WorkflowHistoryAccess::access() allows it.
    *
-   * @param EntityInterface $node
+   * @param \Drupal\Core\Entity\EntityInterface $node
    *   A node object.
    * @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) {
     $form = [];
@@ -96,14 +94,14 @@ class WorkflowTransitionListController extends EntityListController implements C
      * Step 1: generate the Transition Form.
      */
     // 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.
      */
     $view = NULL;
     $moduleHandler = \Drupal::service('module_handler');
-    if ($moduleHandler->moduleExists('views')){
+    if ($moduleHandler->moduleExists('views')) {
       $view = Views::getView('workflow_entity_history');
     }
     if (is_object($view) && $view->storage->status()) {
@@ -119,7 +117,6 @@ class WorkflowTransitionListController extends EntityListController implements C
       // @deprecated. Use the Views display above.
       // Add the history list from programmed WorkflowTransitionListController.
       $entity_type = 'workflow_transition';
-      // $form = $this->listing('workflow_transition');
       $list_builder = $this->entityTypeManager()->getListBuilder($entity_type);
       // Add the Node explicitly, since $list_builder expects a Transition.
       $list_builder->workflow_entity = $entity;
@@ -130,7 +127,6 @@ class WorkflowTransitionListController extends EntityListController implements C
     /*
      * Finally: sort the elements (overriding their weight).
      */
-    // $form['#weight'] = 10;
     $form['actions']['#weight'] = 100;
     $form['table']['#weight'] = 201;
 

+ 4 - 24
sites/all/modules/contrib/admin/workflow/src/Element/WorkflowTransitionElement.php

@@ -24,33 +24,13 @@ use Drupal\workflow\Entity\WorkflowTransitionInterface;
  */
 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.
    *
    * This function is referenced in the Annotation for this class.
    *
    * @param $element
-   * @param FormStateInterface $form_state
+   * @param \Drupal\Core\Form\FormStateInterface $form_state
    * @param $complete_form
    *
    * @return array
@@ -73,7 +53,7 @@ class WorkflowTransitionElement extends FormElement {
    * @example $element += WorkflowTransitionElement::transitionElement($element, $form_state, $form);
    *
    * @param array $element Reference to the form element
-   * @param FormStateInterface $form_state
+   * @param \Drupal\Core\Form\FormStateInterface $form_state
    * @param array $complete_form
    *
    * @return array
@@ -431,7 +411,7 @@ class WorkflowTransitionElement extends FormElement {
    *
    * @param \Drupal\Core\Entity\EntityInterface $transition
    * @param array $form
-   * @param FormStateInterface $form_state
+   * @param \Drupal\Core\Form\FormStateInterface $form_state
    * @param array $item
    *
    * @return WorkflowTransitionInterface
@@ -540,7 +520,7 @@ class WorkflowTransitionElement extends FormElement {
     // but only with a hack on a widget.
     // @todo: Attached fields are not supported in ScheduledTransitions.
     $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) {
       $user_input = isset($form_state->getUserInput()[$field_name]) ? $form_state->getUserInput()[$field_name] : [];
       if (isset($item[$field_name])) {

+ 14 - 1
sites/all/modules/contrib/admin/workflow/src/Entity/Workflow.php

@@ -6,6 +6,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\workflow\WorkflowURLRouteParametersTrait;
 
 /**
  * Workflow configuration entity to persistently store configuration.
@@ -55,6 +56,11 @@ use Drupal\Core\Session\AccountInterface;
  */
 class Workflow extends ConfigEntityBase implements WorkflowInterface {
 
+  /*
+   * Provide URL route parameters for entity links.
+   */
+  use WorkflowURLRouteParametersTrait;
+
   /**
    * The machine name.
    *
@@ -91,6 +97,13 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
    */
   protected $module = 'workflow';
 
+  /**
+   * {@inheritdoc}
+   */
+  public function calculateDependencies() {
+    parent::calculateDependencies();
+  }
+
   /**
    * CRUD functions.
    */
@@ -142,7 +155,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
    */
   public function delete() {
     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()]);
       drupal_set_message($message, 'error');
       return;

+ 16 - 0
sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowConfigTransition.php

@@ -6,6 +6,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\user\UserInterface;
 use Drupal\workflow\WorkflowTypeAttributeTrait;
+use Drupal\workflow\WorkflowURLRouteParametersTrait;
 
 /**
  * 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.
    */
   use WorkflowTypeAttributeTrait;
+  /*
+   * Provide URL route parameters for entity links.
+   */
+  use WorkflowURLRouteParametersTrait;
 
   // Transition data.
   public $id;
@@ -86,12 +91,23 @@ class WorkflowConfigTransition extends ConfigEntityBase implements WorkflowConfi
    * @param $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);
     if($state) {
       $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}
    */

+ 6 - 5
sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowInterface.php

@@ -50,6 +50,7 @@ interface WorkflowInterface {
    *   saved directly in the database. This is because you can use States only
    *   with Transitions, and they rely on State IDs which are generated
    *   magically when saving the State. But you may need a temporary state.
+   *
    * @return \Drupal\workflow\Entity\WorkflowState
    *   The new state.
    */
@@ -71,10 +72,10 @@ interface WorkflowInterface {
    * Uses WorkflowState::getOptions(), because this does an access check.
    * 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).
    * @param $field_name
-   * @param AccountInterface $user
+   * @param \Drupal\Core\Session\AccountInterface $user
    * @param bool $force
    *
    * @return string
@@ -86,10 +87,10 @@ interface WorkflowInterface {
    * Returns the next state for the current state.
    * Is used in VBO Bulk actions.
    *
-   * @param EntityInterface $entity
+   * @param \Drupal\Core\Entity\EntityInterface $entity
    *   The entity at hand.
    * @param $field_name
-   * @param AccountInterface $user
+   * @param \Drupal\Core\Session\AccountInterface $user
    * @param bool $force
    *
    * @return string
@@ -162,7 +163,7 @@ interface WorkflowInterface {
    * @param string $from_sid
    * @param string $to_sid
    *
-   * @return WorkflowConfigTransition[]
+   * @return \Drupal\workflow\Entity\WorkflowConfigTransition[]
    */
   public function getTransitionsByStateId($from_sid, $to_sid);
 

+ 8 - 17
sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowManager.php

@@ -7,12 +7,12 @@ use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
-use Drupal\Core\Entity\Query\QueryFactory;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
 
 /**
  * Manages entity type plugin definitions.
@@ -27,13 +27,6 @@ class WorkflowManager implements WorkflowManagerInterface {
    */
   protected $entityTypeManager;
 
-  /**
-   * The entity query factory.
-   *
-   * @var \Drupal\Core\Entity\Query\QueryFactory
-   */
-  protected $queryFactory;
-
   /**
    * The user settings config object.
    *
@@ -61,20 +54,17 @@ class WorkflowManager implements WorkflowManagerInterface {
    *
    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    *   The entity_type manager service.
-   * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
-   *   The entity query factory.
    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    *   The config factory.
    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
    *   The string translation service.
-   *  @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
    *   The module handler service.
    * @param \Drupal\Core\Session\AccountInterface $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->queryFactory = $query_factory;
     $this->userConfig = $config_factory->get('user.settings');
     $this->stringTranslation = $string_translation;
     $this->moduleHandler = $module_handler;
@@ -165,6 +155,7 @@ class WorkflowManager implements WorkflowManagerInterface {
         $comment = '';
         $old_sid = WorkflowManager::getPreviousStateId($entity, $field_name);
         $new_sid = $entity->$field_name->value;
+        $field_info = FieldStorageConfig::loadByName($entity->getEntityTypeId(), $field_name);
         if ((!$new_sid) && $wid = $field_info->getSetting('workflow_type')) {
           /** @var Workflow $workflow */
           $workflow = Workflow::load($wid);
@@ -309,12 +300,12 @@ class WorkflowManager implements WorkflowManagerInterface {
          */
         $uid = $account->id();
         $new_uid = 0;
-
-        db_update('workflow_transition_history')
+        $database = \Drupal::database();
+        $database->update('workflow_transition_history')
           ->fields(['uid' => $new_uid])
           ->condition('uid', $uid, '=')
           ->execute();
-        db_update('workflow_transition_schedule')
+        $database->update('workflow_transition_schedule')
           ->fields(['uid' => $new_uid])
           ->condition('uid', $uid, '=')
           ->execute();
@@ -405,7 +396,7 @@ class WorkflowManager implements WorkflowManagerInterface {
 
     // Entity is new or in preview or there is no current state. Use previous state.
     // (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);
     }
 

+ 1 - 1
sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowManagerInterface.php

@@ -105,7 +105,7 @@ interface WorkflowManagerInterface {
    * Gets the TransitionWidget in a form (for e.g., Workflow History Tab)
    * @param \Drupal\Core\Entity\EntityInterface $entity
    * @param string $field_name
-   *
+   * @param array $form_state_additions
    * @return
    */
   public static function getWorkflowTransitionForm(EntityInterface $entity, $field_name, array $form_state_additions = []);

+ 19 - 1
sites/all/modules/contrib/admin/workflow/src/Entity/WorkflowState.php

@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\workflow\WorkflowTypeAttributeTrait;
+use Drupal\workflow\WorkflowURLRouteParametersTrait;
 
 /**
  * Workflow configuration entity to persistently store configuration.
@@ -59,6 +60,10 @@ class WorkflowState extends ConfigEntityBase {
    * Add variables and get/set methods for Workflow property.
    */
   use WorkflowTypeAttributeTrait;
+  /*
+   * Provide URL route parameters for entity links.
+   */
+  use WorkflowURLRouteParametersTrait;
 
   /**
    * The machine name.
@@ -125,6 +130,19 @@ class WorkflowState extends ConfigEntityBase {
     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}
    */
@@ -179,7 +197,7 @@ class WorkflowState extends ConfigEntityBase {
     $states = parent::loadMultiple();
     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.
     $result = [];
     foreach ($states as $state) {

+ 2 - 1
sites/all/modules/contrib/admin/workflow/src/Plugin/Action/WorkflowStateActionBase.php

@@ -56,7 +56,8 @@ abstract class WorkflowStateActionBase extends ConfigurableActionBase implements
   }
 
   /**
-   * @param EntityInterface $entity
+   * @param \Drupal\Core\Entity\EntityInterface $entity
+   *
    * @return \Drupal\workflow\Entity\WorkflowTransitionInterface
    */
   protected function getTransitionForExecution(EntityInterface $entity) {

+ 1 - 1
sites/all/modules/contrib/admin/workflow/src/Plugin/Block/WorkflowTransitionBlock.php

@@ -67,7 +67,7 @@ class WorkflowTransitionBlock extends BlockBase {
      * Output: generate the Transition Form.
      */
     // Add the WorkflowTransitionForm to the page.
-    $form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name);
+    $form = WorkflowManager::getWorkflowTransitionForm($entity, $field_name, []);
 
     return $form;
   }

+ 1 - 1
sites/all/modules/contrib/admin/workflow/src/Plugin/Field/FieldFormatter/WorkflowDefaultFormatter.php

@@ -175,7 +175,7 @@ class WorkflowDefaultFormatter extends FormatterBase implements ContainerFactory
     // BEGIN Copy from CommentDefaultFormatter
     $elements['#cache']['contexts'][] = 'user.permissions';
     // 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.
     $elements['#cache']['contexts'][] = 'user.roles';

+ 1 - 1
sites/all/modules/contrib/admin/workflow/src/Plugin/Field/FieldType/WorkflowItem.php

@@ -270,7 +270,7 @@ class WorkflowItem extends ListItemBase {
    *
    * 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
    *   labels.
    *

+ 7 - 1
sites/all/modules/contrib/admin/workflow/src/Plugin/Field/FieldWidget/WorkflowDefaultWidget.php

@@ -95,7 +95,13 @@ class WorkflowDefaultWidget extends WidgetBase {
     $element['#default_value'] = $transition;
     $element += WorkflowTransitionElement::transitionElement($element, $form_state, $form);
     // 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.
     $attached_fields = WorkflowManager::getAttachedFields('workflow_transition', $wid);
     foreach ($attached_fields as $key => $attached_field) {

+ 1 - 1
sites/all/modules/contrib/admin/workflow/src/Plugin/Validation/Constraint/WorkflowFieldConstraintValidator.php

@@ -64,7 +64,7 @@ class WorkflowFieldConstraintValidator extends ConstraintValidator implements Co
   }
 
   /**
-   * @param FieldStorageConfig $field_storage
+   * @param \Drupal\field\Entity\FieldStorageConfig $field_storage
    *
    * @return bool
    */

+ 23 - 0
sites/all/modules/contrib/admin/workflow/src/Plugin/views/argument/WorkflowState.php

@@ -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);
+  }
+
+}

+ 9 - 10
sites/all/modules/contrib/admin/workflow/src/Routing/RouteSubscriber.php

@@ -41,17 +41,16 @@ class RouteSubscriber extends RouteSubscriberBase {
     foreach ($field_list as $entityTypeId => $fields) {
 
       /*
-       * @todo Create a Entity workflow field list page and a route
-       * that redirect to the page when a entity have more than
-       * one workflow fields.
+       * @todo: For entities with +1 workflow fields, Create an
+       * Entity workflow field list page and a route
+       * 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}.
-      if (count($fields) < 2) {
-        $path = "/$entityTypeId/{{$entityTypeId}}/workflow";
-        $route = $this->getEntityLoadRoute($entityTypeId, $path);
-        $collection->add("entity.$entityTypeId.workflow_history", $route);
-      }
+      // Generate route for default field. Redirect to workflow/{field_name}.
+      $path = "/$entityTypeId/{{$entityTypeId}}/workflow";
+      $route = $this->getEntityLoadRoute($entityTypeId, $path);
+      $collection->add("entity.$entityTypeId.workflow_history", $route);
 
       // Generate one route for each workflow field.
       foreach ($fields as $field_name => $field) {
@@ -133,4 +132,4 @@ class RouteSubscriber extends RouteSubscriberBase {
     return $availableItems;
   }
 
-}
+}

+ 5 - 3
sites/all/modules/contrib/admin/workflow/src/WorkflowTypeAttributeTrait.php

@@ -27,14 +27,14 @@ trait WorkflowTypeAttributeTrait {
    * It must explicitly be defined, and not be public, to avoid errors
    * when exporting with json_encode().
    *
-   * @var Workflow
+   * @var \Drupal\workflow\Entity\Workflow
    */
   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->workflow = NULL;
     if ($workflow) {
@@ -64,6 +64,8 @@ trait WorkflowTypeAttributeTrait {
   /**
    * Sets the Workflow ID of this object.
    *
+   * @param $wid Workflow ID
+   *
    * @return object
    */
   public function setWorkflowId($wid) {

+ 19 - 0
sites/all/modules/contrib/admin/workflow/src/WorkflowURLRouteParametersTrait.php

@@ -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;
+  }
+
+}

+ 3 - 3
sites/all/modules/contrib/admin/workflow/workflow.api.php

@@ -25,7 +25,7 @@ use Drupal\workflow\Entity\WorkflowTransitionInterface;
  *   'operations': Allow modules to insert their own workflow operations.
  *   'workflow':  Allow modules to insert workflow 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.
  *
  * @return array
@@ -87,9 +87,9 @@ function hook_workflow_operations($op, EntityInterface $entity = NULL) {
  * @param string $op
  *   The current workflow operation.
  *   E.g., 'transition pre', 'transition post'.
- * @param WorkflowTransitionInterface $transition
+ * @param \Drupal\workflow\Entity\WorkflowTransitionInterface $transition
  *   The transition, that contains all of the above.
- * @param UserInterface $user
+ * @param \Drupal\user\UserInterface $user
  *
  * @return bool|void
  */

+ 3 - 3
sites/all/modules/contrib/admin/workflow/workflow.info.yml

@@ -10,8 +10,8 @@ dependencies:
   - options
   - user
 
-# Information added by Drupal.org packaging script on 2018-04-29
-version: '8.x-1.1'
+# Information added by Drupal.org packaging script on 2018-09-04
+version: '8.x-1.1+18-dev'
 core: '8.x'
 project: 'workflow'
-datestamp: 1525039388
+datestamp: 1536080308

+ 10 - 5
sites/all/modules/contrib/admin/workflow/workflow.module

@@ -526,7 +526,7 @@ function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle
             else {
               // 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);
               // @todo ?? Loop over bundles?
               /** @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.
  *
  * @param \Drupal\Core\Entity\EntityInterface|null $entity
+ * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *
  * @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) {
     return $entity;
   }
 
+  if (!$route_match) {
+    $route_match = \Drupal::routeMatch();
+  }
+
   $entities = [];
-  foreach (\Drupal::routeMatch()->getParameters() as $param) {
+  foreach ($route_match->getParameters() as $param) {
     if ($param instanceof \Drupal\Core\Entity\EntityInterface) {
       $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.
     // This is an indicator that the route is mal-configured.
     workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'route declaration is not optimal.');
-    $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value);
-    return $entity;
+    // return $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value);
+    return NULL;
   }
 
   return $value;

+ 1 - 1
sites/all/modules/contrib/admin/workflow/workflow.services.yml

@@ -1,7 +1,7 @@
 services:
   workflow.manager:
     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:
     class: Drupal\workflow\Routing\RouteSubscriber

+ 12 - 4
sites/all/modules/contrib/admin/workflow/workflow.views.inc

@@ -7,6 +7,8 @@
  * @ingroup views_module_handlers
  */
 
+use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\workflow\Entity\WorkflowManager;
 use Drupal\field\FieldStorageConfigInterface;
 
 /**
@@ -18,10 +20,16 @@ function workflow_field_views_data(FieldStorageConfigInterface $field) {
 
   foreach ($data as $table_name => $table_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']['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) {
   // 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) {
-    if (\Drupal\workflow\Entity\WorkflowManager::isWorkflowEntityType($entity_type_id)) {
+    if (WorkflowManager::isWorkflowEntityType($entity_type_id)) {
       continue;
     }
-    if (!$entity_type->entityClassImplements(\Drupal\Core\Entity\ContentEntityInterface::class)) {
+    if (!$entity_type->entityClassImplements(ContentEntityInterface::class)) {
       continue;
     }
     if (!$entity_type->getBaseTable()) {