本文整理汇总了PHP中Workflow::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Workflow::load方法的具体用法?PHP Workflow::load怎么用?PHP Workflow::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workflow
的用法示例。
在下文中一共展示了Workflow::load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
/**
* Returns the allowed values for the current state.
*
* @deprecated workflow_field_choices() --> WorkflowState->getOptions()
*/
public function getOptions($entity_type, $entity, $force = FALSE)
{
global $user;
static $cache = array();
// Entity-specific cache per page load.
$options = array();
if (!$entity) {
// If no entity is given, no result (e.g., on a Field settings page).
$options = array();
return $options;
}
$entity_id = entity_id($entity_type, $entity);
$current_sid = $this->sid;
// Get options from page cache.
if (isset($cache[$entity_type][$entity_id][$force][$current_sid])) {
$options = $cache[$entity_type][$entity_id][$force][$current_sid];
return $options;
}
$workflow = Workflow::load($this->wid);
if ($workflow) {
$roles = array_keys($user->roles);
// If this is a new page, give the authorship role.
if (!$entity_id) {
$roles = array_merge(array('author'), $roles);
} elseif (isset($entity->uid) && $entity->uid == $user->uid && $user->uid > 0) {
$roles = array_merge(array('author'), $roles);
}
// Superuser is special. And $force allows Rules to cause transition.
if ($user->uid == 1 || $force) {
$roles = 'ALL';
}
// Workflow_allowable_transitions() does not return the entire transition row. Would like it to, but doesn't.
// Instead it returns just the allowable data as:
// [tid] => 1 [state_id] => 1 [state_name] => (creation) [state_weight] => -50
$transitions = workflow_allowable_transitions($current_sid, 'to', $roles);
// Include current state if it is not the (creation) state.
foreach ($transitions as $transition) {
if ($transition->sysid != WORKFLOW_CREATION && !$force) {
// Invoke a callback indicating that we are collecting state choices.
// Modules may veto a choice by returning FALSE.
// In this case, the choice is never presented to the user.
// @todo: for better performance, call a hook only once: can we find a way to pass all transitions at once
$result = module_invoke_all('workflow', 'transition permitted', $current_sid, $transition->state_id, $entity, $field_name = '');
// Did anybody veto this choice?
if (!in_array(FALSE, $result)) {
// If not vetoed, add to list.
$options[$transition->state_id] = check_plain(t($transition->state_name));
}
}
}
// Save to entity-specific cache.
$cache[$entity_type][$entity_id][$force][$current_sid] = $options;
}
return $options;
}
示例2: formElement
/**
* Implements hook_field_widget_form --> WidgetInterface::formElement().
*
* {@inheritdoc}
*
* Be careful: this widget may be shown in very different places. Test carefully!!
* - On a entity add/edit page
* - On a entity preview page
* - On a entity view page
* - On a entity 'workflow history' tab
* - On a comment display, in the comment history
* - On a comment form, below the comment history
* @todo D8: change "array $items" to "FieldInterface $items"
*/
public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state)
{
$field_name = $this->field['field_name'];
$field = $this->instance;
$instance = $this->instance;
$entity = $this->entity;
$entity_type = $this->entity_type;
$entity_id = entity_id($entity_type, $entity);
if (!$entity) {
// If no entity given, do not show a form. E.g., on the field settings page.
return $element;
}
// Capture settings to format the form/widget.
$settings_title_as_name = !empty($this->field['settings']['widget']['name_as_title']);
// The schedule cannot be shown on a Content add page.
$settings_schedule = !empty($this->field['settings']['widget']['schedule']) && $entity_id;
$settings_schedule_timezone = !empty($this->field['settings']['widget']['schedule_timezone']);
// Show comment, when both Field and Instance allow this.
$settings_comment = $this->field['settings']['widget']['comment'] ? 'textarea' : 'hidden';
$workflow = Workflow::load($this->field['settings']['wid']);
$current_sid = workflow_node_current_state($entity, $entity_type, $field_name);
$current_state = WorkflowState::load($current_sid);
$options = array();
$options = $current_state->getOptions($entity_type, $entity);
// Determine the default value. If we are in CreationState, use a fast alternative for $workflow->getFirstSid().
$default_value = $current_state->isCreationState() ? key($options) : $current_sid;
// Get the scheduling info. This may change the $current_sid on the Form.
$scheduled = '0';
$timestamp = REQUEST_TIME;
$comment = NULL;
if ($settings_schedule) {
// Read scheduled information.
// Technically you could have more than one scheduled, but this will only add the soonest one.
foreach (WorkflowScheduledTransition::load($entity_type, $entity_id, $field_name) as $scheduled_transition) {
$scheduled = '1';
$current_sid = $scheduled_transition->sid;
$timestamp = $scheduled_transition->scheduled;
$comment = $scheduled_transition->comment;
break;
}
}
// Fetch the form ID. This is unique for each entity, to allow multiple form per page (Views, etc.).
$form_id = $form_state['build_info']['form_id'];
$element_scheduled_name = 'workflow_scheduled_' . $form_id;
$element_options_name = 'workflow_options_' . $form_id;
$element_scheduled_name = 'workflow_scheduled';
$element_options_name = 'workflow_options';
$elt_state_name = 'workflow_scheduled_' . $form_id;
$label = $workflow->label();
// Prepare a wrapper. This might be a fieldset.
$element['workflow']['#type'] = 'container';
$element['workflow']['#attributes'] = array('class' => array('workflow-form-container'));
// Save the current value of the node in the form, for later Workflow-module specific references.
// We add prefix, since #tree == FALSE.
$element['workflow']['workflow_entity'] = array('#type' => 'value', '#value' => $this->entity);
$element['workflow']['workflow_entity_type'] = array('#type' => 'value', '#value' => $this->entity_type);
$element['workflow']['workflow_field'] = array('#type' => 'value', '#value' => $this->field);
$element['workflow']['workflow_instance'] = array('#type' => 'value', '#value' => $this->instance);
// Save the form_id, so the form values can be retrieved in submit function.
$element['workflow']['form_id'] = array('#type' => 'value', '#value' => $form_id);
// First of all, we add the default value in the place were normal fields
// have it. This is to cater for 'preview' of the entity.
$element['#default_value'] = $default_value;
// Decide if we show a widget or a formatter.
// There is no need to a widget when the only choice is the current sid.
if (!$current_state->showWidget($options)) {
$element['workflow'][$element_options_name] = workflow_state_formatter($entity_type, $entity, $field, $instance);
return $element;
} else {
$element['workflow'][$element_options_name] = array('#type' => $this->field['settings']['widget']['options'], '#title' => $settings_title_as_name ? t('Change !name state', array('!name' => $label)) : '', '#options' => $options, '#default_value' => $default_value);
}
// Display scheduling form, but only if entity is being edited and user has
// permission. State change cannot be scheduled at entity creation because
// that leaves the entity in the (creation) state.
if ($settings_schedule == TRUE && user_access('schedule workflow transitions')) {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) {
$timezone = $user->timezone;
} else {
$timezone = variable_get('date_default_timezone', 0);
}
$timezones = drupal_map_assoc(timezone_identifiers_list());
$hours = format_date($timestamp, 'custom', 'H:i', $timezone);
// $element['workflow']['workflow_scheduled'] = array(
$element['workflow'][$element_scheduled_name] = array('#type' => 'radios', '#title' => t('Schedule'), '#options' => array('0' => t('Immediately'), '1' => t('Schedule for state change')), '#default_value' => $scheduled, '#attributes' => array('id' => 'scheduled_' . $form_id));
$element['workflow']['workflow_scheduled_date_time'] = array('#type' => 'fieldset', '#title' => t('At'), '#attributes' => array('class' => array('container-inline')), '#prefix' => '<div style="margin-left: 1em;">', '#suffix' => '</div>', '#states' => array('visible' => array(':input[id="' . 'scheduled_' . $form_id . '"]' => array('value' => '1'))));
//.........这里部分代码省略.........
示例3: save
/**
* Given information, update or insert a new workflow.
*
* @deprecated: workflow_update_workflows() --> Workflow->save()
*/
public function save($create_creation_state = TRUE)
{
$wid = $this->wid;
if (isset($this->tab_roles) && is_array($this->tab_roles)) {
$this->tab_roles = implode(',', $this->tab_roles);
}
if (is_array($this->options)) {
$this->options = serialize($this->options);
}
if ($wid > 0 && Workflow::load($wid)) {
drupal_write_record('workflows', $this, 'wid');
} else {
drupal_write_record('workflows', $this);
if ($create_creation_state) {
$creation_state = $this->getCreationState();
$creation_state->save();
}
}
// Update the page cache.
self::$workflows[$wid] = $this;
}