You are here

workflow_devel.module in Workflow 8

Development tools for Workflow.

File

modules/workflow_devel/workflow_devel.module
View source
<?php

/**
 * @file
 * Development tools for Workflow.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\UserInterface;
use Drupal\workflow\Entity\WorkflowTransitionInterface;
module_load_include('php', 'workflow', 'workflow.api');

/* Hooks defined by workflow module. */

/**
 * @inheritdoc
 */
function workflow_devel_workflow_operations($op, EntityInterface $entity = NULL) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, $op, '');
  return hook_workflow_operations($op, $entity);
}

/* Hooks defined by workflow module. */

/**
 * @inheritdoc
 */
function workflow_devel_workflow($op, WorkflowTransitionInterface $transition, UserInterface $user) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, $op, '');
  return hook_workflow($op, $transition, $user);
}

/**
 * @inheritdoc
 */
function workflow_devel_workflow_comment_alter(&$comment, array &$context) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, $comment, '');
  hook_workflow_comment_alter($comment, $context);
}

/**
 * @inheritdoc
 */
function workflow_devel_workflow_history_alter(array &$context) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__);
  hook_workflow_history_alter($context);
}

/**
 * @inheritdoc
 */
function workflow_devel_workflow_permitted_state_transitions_alter(array &$transitions, array $context) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__);
  hook_workflow_permitted_state_transitions_alter($transitions, $context);
}

/* Hooks defined by core Form API: Change the Workflow Transition Form. */

/**
 * Alter forms for field widgets provided by other modules.
 *
 * @param array $element
 *   The field widget form element as constructed by hook_field_widget_form().
 * @param FormStateInterface $form_state
 *   An associative array containing the current state of the form.
 * @param array $context
 *   An associative array containing the following key-value pairs, matching the
 *   arguments received by hook_field_widget_form():
 *   - form: The form structure to which widgets are being attached. This may be
 *     a full form structure, or a sub-element of a larger form.
 *   - field: The field structure.
 *   - instance: The field instance structure.
 *   - langcode: The language associated with $items.
 *   - items: Array of default values for this field.
 *   - delta: The order of this item in the array of subelements (0, 1, 2, etc).
 *
 * @see hook_field_widget_form()
 * @see hook_field_widget_WIDGET_TYPE_form_alter()
 */
function workflow_devel_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {

  // A hook for changing any widget. Better not use it: it is called on EVERY
  // Widget. (Even though the message is only shown once.)
  // D7: This hook is introduced in Drupal 7.8.
  // workflow_debug(__FILE__, __FUNCTION__, __LINE__, '', '');
  // dpm($context['widget']->getPluginId());
  hook_field_widget_form_alter($element, $form_state, $context);
}

/**
 * @inheritdoc
 */
function workflow_devel_field_widget_workflow_default_form_alter(&$element, FormStateInterface $form_state, $context) {

  // A hook specific for the 'workflow_default' widget.
  // D7: This hook is introduced in Drupal 7.8.
  // D8: This name is specified in the annotation of WorkflowDefaultWidget.
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, '', '');
  hook_field_widget_workflow_default_form_alter($element, $form_state, $context);
}

/**
 * @inheritdoc
 */
function workflow_devel_form_workflow_transition_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, $form_id, '');
  hook_form_workflow_transition_form_alter($form, $form_state, $form_id);
}

/**
 * @inheritdoc
 */
function workflow_devel_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (substr($form_id, 0, 8) == 'workflow') {
    workflow_debug(__FILE__, __FUNCTION__, __LINE__, $form_id, '');
  }
  hook_form_alter($form, $form_state, $form_id);
}

/**
 * Hooks defined by core: Change the operations column in an Entity list.
 *
 * @see EntityListBuilder::getOperations()
 *
 * @return array
 */
function workflow_devel_entity_operation($entities) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, '', '');
  $operations = [];
  return $operations;
}

/**
 * @inheritdoc
 */
function workflow_devel_entity_operation_alter(array $operations, EntityInterface $entity) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, $entity
    ->getEntityTypeId(), $entity
    ->id());
}

/*
 * Hooks defined by core: hook_entity_CRUD.
 *
 * @see hook_entity_create(), hook_entity_update(), etc.
 * @see hook_ENTITY_TYPE_create(), hook_ENTITY_TYPE_update(), etc.
 */

/**
 * @inheritdoc
 */
function workflow_devel_entity_create(EntityInterface $entity) {

  // workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'create', $entity->getEntityTypeId());
}

/**
 * @inheritdoc
 */
function workflow_devel_entity_presave(EntityInterface $entity) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'presave', $entity
    ->getEntityTypeId());
}

/**
 * @inheritdoc
 */
function workflow_devel_entity_insert(EntityInterface $entity) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'insert', $entity
    ->getEntityTypeId());
}

/**
 * @inheritdoc
 */
function workflow_devel_entity_update(EntityInterface $entity) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'update', $entity
    ->getEntityTypeId());
}

/**
 * @inheritdoc
 */
function workflow_devel_entity_predelete(EntityInterface $entity) {
  if (substr($entity
    ->getEntityTypeId(), 0, 8) == 'workflow') {
    workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'predelete', $entity
      ->getEntityTypeId());
  }
  hook_entity_predelete($entity);
}

/**
 * @inheritdoc
 */
function workflow_devel_entity_delete(EntityInterface $entity) {
  workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'delete', $entity
    ->getEntityTypeId());
  hook_entity_delete($entity);
}