You are here

class WorkflowConfigTransition in Workflow 7.2

Implements a configurated Transition.

Hierarchy

Expanded class hierarchy of WorkflowConfigTransition

8 string references to 'WorkflowConfigTransition'
Workflow::createTransition in includes/Entity/Workflow.php
Creates a Transition for this workflow.
Workflow::getTransitions in includes/Entity/Workflow.php
@inheritdoc
Workflow::rebuildInternals in includes/Entity/Workflow.php
Rebuild internals that get saved separately.
WorkflowConfigTransition::__construct in includes/Entity/WorkflowConfigTransition.php
workflow_entity_info in ./workflow.entity.inc
Implements hook_entity_info().

... See full list

File

includes/Entity/WorkflowConfigTransition.php, line 12
Contains workflow\includes\Entity\WorkflowConfigTransition. Contains workflow\includes\Entity\WorkflowConfigTransitionController.

View source
class WorkflowConfigTransition extends Entity {

  // Transition data.
  public $tid = 0;

  // public $old_sid = 0;
  // public $new_sid = 0;
  public $sid = 0;

  // @todo D8: remove $sid, use $new_sid. (requires conversion of Views displays.)
  public $target_sid = 0;
  public $roles = array();

  // Extra fields.
  public $wid = 0;

  // The following must explicitely defined, and not be public, to avoid errors when exporting with json_encode().
  protected $workflow = NULL;

  /**
   * Entity class functions.
   */

  /*
   // Implementing clone needs a list of tid-less transitions, and a conversion
   // of sids for both States and ConfigTransitions.
   // public function __clone() {}
  */
  public function __construct(array $values = array(), $entityType = NULL) {

    // Please be aware that $entity_type and $entityType are different things!
    return parent::__construct($values, $entityType = 'WorkflowConfigTransition');
  }

  /**
   * Permanently deletes the entity.
   */
  public function delete() {

    // Notify any interested modules before we delete, in case there's data needed.
    // @todo D8: this can be replaced by a hook_entity_delete(?)
    module_invoke_all('workflow', 'transition delete', $this->tid, NULL, NULL, FALSE);
    return parent::delete();
  }
  protected function defaultLabel() {
    return isset($this->label) ? t('@label', array(
      '@label' => $this->label,
    )) : '';
  }
  protected function defaultUri() {
    $wid = $this->wid;
    return array(
      'path' => WORKFLOW_ADMIN_UI_PATH . "/manage/{$wid}/transitions/",
    );
  }

  /**
   * Property functions.
   */

  /**
   * Returns the Workflow object of this State.
   *
   * @param Workflow $workflow
   *   An optional workflow object. Can be used as a setter.
   *
   * @return Workflow
   *   Workflow object.
   */
  public function setWorkflow($workflow) {
    $this->wid = $workflow->wid;
    $this->workflow = $workflow;
  }
  public function getWorkflow() {
    if (isset($this->workflow)) {
      return $this->workflow;
    }
    return workflow_load_single($this->wid);
  }
  public function getOldState() {
    return workflow_state_load_single($this->sid);
  }
  public function getNewState() {
    return workflow_state_load_single($this->target_sid);
  }

  /**
   * Verifies if the given transition is allowed.
   *
   * - In settings;
   * - In permissions;
   * - By permission hooks, implemented by other modules.
   *
   * @param string|array $user_roles
   *   The string 'ALL' to force allowing the transition, or an array of role
   *   IDs to compare against the roles allowed for the transition.
   *
   * @return bool
   *   If the transition is allowed, this function returns TRUE. Otherwise, it
   *   returns FALSE.
   */
  public function isAllowed($user_roles) {
    if ($user_roles === 'ALL') {

      // Superuser.
      return TRUE;
    }
    elseif ($user_roles) {
      return array_intersect($user_roles, $this->roles) == TRUE;
    }
    return TRUE;
  }

  /**
   * Generate a machine name for a transition.
   */
  public static function machineName($start_name, $end_name) {
    $new_name = sprintf("%s_to_%s", $start_name, $end_name);

    // Special case: replace parens in creation state transition names.
    $new_name = str_replace("(creation)", "_creation", $new_name);
    return $new_name;
  }
  public function save() {
    parent::save();

    // Ensure Workflow is marked overridden.
    $workflow = $this
      ->getWorkflow();
    if ($workflow->status == ENTITY_IN_CODE) {
      $workflow->status = ENTITY_OVERRIDDEN;
      $workflow
        ->save();
    }
  }

  /**
   * Helper debugging function to easily show the contents of a transition.
   */
  public function dpm($function = 'not_specified') {
    $transition = $this;
    $time = NULL;

    // Do this extensive $user_name lines, for some troubles with Action.
    $t_string = get_class($this) . ' ' . $this
      ->identifier() . " in function '{$function}'";

    //$output[] = 'Entity  = ' . ((!$entity) ? 'NULL' : ($entity_type . '/' . $entity_bundle . '/' . $entity_id));

    //$output[] = 'Field   = ' . $transition->getFieldName();
    $output[] = 'From/To = ' . $transition->sid . ' > ' . $transition->target_sid . ' @ ' . $time;

    //$output[] = 'Comment = ' . $user_name . ' says: ' . $transition->getComment();

    //$output[] = 'Forced  = ' . ($transition->isForced() ? 'yes' : 'no');
    if (function_exists('dpm')) {
      dpm($output, $t_string);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$defaultLabel protected property 1
Entity::$entityInfo protected property
Entity::$entityType protected property
Entity::$idKey protected property
Entity::$wrapper protected property
Entity::buildContent public function Builds a structured array representing the entity's content. Overrides EntityInterface::buildContent 1
Entity::bundle public function Returns the bundle of the entity. Overrides EntityInterface::bundle
Entity::entityInfo public function Returns the info of the type of the entity. Overrides EntityInterface::entityInfo
Entity::entityType public function Returns the type of the entity. Overrides EntityInterface::entityType
Entity::export public function Exports the entity. Overrides EntityInterface::export
Entity::getTranslation public function Gets the raw, translated value of a property or field. Overrides EntityInterface::getTranslation
Entity::hasStatus public function Checks if the entity has a certain exportable status. Overrides EntityInterface::hasStatus
Entity::identifier public function Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface::identifier
Entity::internalIdentifier public function Returns the internal, numeric identifier. Overrides EntityInterface::internalIdentifier
Entity::isDefaultRevision public function Checks whether the entity is the default revision. Overrides EntityInterface::isDefaultRevision
Entity::label public function Returns the label of the entity. Overrides EntityInterface::label
Entity::setUp protected function Set up the object instance on construction or unserializiation.
Entity::uri public function Returns the uri of the entity just as entity_uri(). Overrides EntityInterface::uri
Entity::view public function Generate an array for rendering the entity. Overrides EntityInterface::view
Entity::wrapper public function Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface::wrapper
Entity::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
WorkflowConfigTransition::$roles public property
WorkflowConfigTransition::$sid public property
WorkflowConfigTransition::$target_sid public property
WorkflowConfigTransition::$tid public property
WorkflowConfigTransition::$wid public property
WorkflowConfigTransition::$workflow protected property
WorkflowConfigTransition::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. Overrides Entity::defaultLabel
WorkflowConfigTransition::defaultUri protected function Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). Overrides Entity::defaultUri
WorkflowConfigTransition::delete public function Permanently deletes the entity. Overrides Entity::delete
WorkflowConfigTransition::dpm public function Helper debugging function to easily show the contents of a transition.
WorkflowConfigTransition::getNewState public function
WorkflowConfigTransition::getOldState public function
WorkflowConfigTransition::getWorkflow public function
WorkflowConfigTransition::isAllowed public function Verifies if the given transition is allowed.
WorkflowConfigTransition::machineName public static function Generate a machine name for a transition.
WorkflowConfigTransition::save public function Permanently saves the entity. Overrides Entity::save
WorkflowConfigTransition::setWorkflow public function Returns the Workflow object of this State.
WorkflowConfigTransition::__construct public function Overrides Entity::__construct