本文整理汇总了PHP中entity_id函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_id函数的具体用法?PHP entity_id怎么用?PHP entity_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: alterItems
public function alterItems(array &$items)
{
// Prevent session information from being saved while indexing.
drupal_save_session(FALSE);
// Force the current user to anonymous to prevent access bypass in search
// indexes.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
$entity_type = $this->index->getEntityType();
$entity_handler = panelizer_entity_plugin_get_handler($entity_type);
foreach ($items as &$item) {
$entity_id = entity_id($entity_type, $item);
$item->search_api_panelizer_content = NULL;
$item->search_api_panelizer_title = NULL;
try {
if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
$item->search_api_panelizer_content = $render_info['content'];
$item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
}
} catch (Exception $e) {
watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
}
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
}
开发者ID:michael-wojcik,项目名称:open_eggheads,代码行数:27,代码来源:PanelizerSearchApiAlterCallback.class.php
示例2: alterItems
public function alterItems(array &$items)
{
// Prevent session information from being saved while indexing.
drupal_save_session(FALSE);
// Force the current user to anonymous to prevent access bypass in search
// indexes.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
$entity_type = $this->index->getEntityType();
$entity_handler = panelizer_entity_plugin_get_handler($entity_type);
foreach ($items as &$item) {
$entity_id = entity_id($entity_type, $item);
$item->search_api_panelizer_content = NULL;
$item->search_api_panelizer_title = NULL;
// If Search API specifies a language to view the item in, force the
// global language_content to be Search API item language. Fieldable
// panel panes will render in the correct language.
if (isset($item->search_api_language)) {
global $language_content;
$original_language_content = $language_content;
$languages = language_list();
if (isset($languages[$item->search_api_language])) {
$language_content = $languages[$item->search_api_language];
} else {
$language_content = language_default();
}
}
try {
if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
$item->search_api_panelizer_content = $render_info['content'];
$item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
}
} catch (Exception $e) {
watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
}
// Restore the language_content global if it was overridden.
if (isset($original_language_content)) {
$language_content = $original_language_content;
}
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
}
开发者ID:GitError404,项目名称:favrskov.dk,代码行数:44,代码来源:PanelizerSearchApiAlterCallback.class.php
示例3: overviewTableRow
protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array())
{
$entity_uri = entity_uri($this->entityType, $entity);
$row[] = array('data' => array('#theme' => 'entity_ui_overview_item', '#label' => entity_label($this->entityType, $entity), '#name' => !empty($this->entityInfo['exportable']) ? entity_id($this->entityType, $entity) : FALSE, '#url' => $entity_uri ? $entity_uri : FALSE, '#entity_type' => $this->entityType));
// Add in any passed additional cols.
foreach ($additional_cols as $col) {
$row[] = $col;
}
// Add a row for the exportable status.
if (!empty($this->entityInfo['exportable'])) {
$row[] = array('data' => array('#theme' => 'entity_status', '#status' => $entity->{$this->statusKey}));
}
// In case this is a bundle, we add links to the field ui tabs.
$field_ui = !empty($this->entityInfo['bundle of']) && entity_type_is_fieldable($this->entityInfo['bundle of']) && module_exists('field_ui');
// For exportable entities we add an export link.
$exportable = !empty($this->entityInfo['exportable']);
// If i18n integration is enabled, add a link to the translate tab.
$i18n = !empty($this->entityInfo['i18n controller class']);
// Add operations depending on the status.
if (entity_has_status($this->entityType, $entity, ENTITY_FIXED)) {
$row[] = array('data' => l(t('clone'), $this->path . '/manage/' . $id . '/clone'), 'colspan' => $this->operationCount());
} else {
$row[] = l(t('edit'), $this->path . '/manage/' . $id);
if (empty($this->entityInfo['exportable']) || !entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
$row[] = l(t('delete'), $this->path . '/manage/' . $id . '/delete', array('query' => drupal_get_destination()));
} else {
$row[] = '';
}
}
if ($exportable) {
$row[] = l(t('export'), $this->path . '/manage/' . $id . '/export');
}
$row[] = $entity->product_quantity;
$row[] = l(t('quick+1'), '/product/' . $id . '/add/1');
$row[] = l(t('quick-1'), '/product/' . $id . '/sub/1');
return $row;
}
开发者ID:scothiam,项目名称:d7_entities,代码行数:37,代码来源:ProductEntityUIController.php
示例4: hook_field_collection_item_delete
/**
* Responds to field collection item deletion.
*
* This hook is invoked after the field collection item has been removed from
* the database.
*
* @param FieldCollectionItemEntity $field_collection_item
* The field collection item that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_field_collection_item_delete(FieldCollectionItemEntity $field_collection_item)
{
db_delete('mytable')->condition('pid', entity_id('field_collection_item', $field_collection_item))->execute();
}
开发者ID:ehazell,项目名称:AWBA,代码行数:15,代码来源:field_collection.api.php
示例5: applyOperation
/**
* Overrides the 'revert' action, to not delete the workflows.
*
* @see https://www.drupal.org/node/2051079
* @see https://www.drupal.org/node/1043634
*/
public function applyOperation($op, $entity)
{
$label = entity_label($this->entityType, $entity);
$vars = array('%entity' => $this->entityInfo['label'], '%label' => $label);
$id = entity_id($this->entityType, $entity);
$edit_link = l(t('edit'), $this->path . '/manage/' . $id . '/edit');
switch ($op) {
case 'revert':
// Do not delete the workflow, but recreate features_get_default($entity_type, $module);
// entity_delete($this->entityType, $id);
$workflow = $entity;
$entity_type = $this->entityType;
$funcname = $workflow->module . '_default_' . $this->entityType;
$defaults = $funcname();
// No defaults, no processing.
if (empty($defaults)) {
return;
}
foreach ($defaults as $name => $entity) {
$existing[$name] = workflow_load($name);
// If we got an existing entity with the same name, we reuse its entity id.
if (isset($existing[$name])) {
// Set the original as later reference.
$entity->original = $existing[$name];
// As we got an ID, the entity is not new.
$entity->wid = $entity->original->wid;
unset($entity->is_new);
// Update the status to be in code.
// $entity->status |= ENTITY_IN_CODE;
$entity->status = ENTITY_IN_CODE;
// We mark it for being in revert mode.
$entity->is_reverted = TRUE;
entity_save($entity_type, $entity);
unset($entity->is_reverted);
}
// The rest of the defaults is handled by default implementation.
// @see entity_defaults_rebuild()
}
watchdog($this->entityType, 'Reverted %entity %label to the defaults.', $vars, WATCHDOG_NOTICE, $edit_link);
return t('Reverted %entity %label to the defaults.', $vars);
case 'delete':
case 'import':
default:
return parent::applyOperation($op, $entity);
}
}
开发者ID:TabulaData,项目名称:donl_d7,代码行数:52,代码来源:EntityWorkflowUIController.php
示例6: update
/**
* Implements hook_field_update() -> FieldItemInterface::update().
*
* @todo: in course of time, this is not used anymore...
* It is called also from hook_field_insert(), since we need $nid to store {workflow_node_history}.
* We cannot use hook_field_presave(), since $nid is not yet known at that moment.
*
* "Contrary to the old D7 hooks, the methods do not receive the parent entity
* "or the langcode of the field values as parameters. If needed, those can be accessed
* "by the getEntity() and getLangcode() methods on the Field and FieldItem classes.
*/
public function update(&$items)
{
// ($entity_type, $entity, $field, $instance, $langcode, &$items) {
// @todo: apparentlly, in course of time, this is not used anymore. Restore or remove.
$field_name = $this->field['field_name'];
$wid = $this->field['settings']['wid'];
$new_state = WorkflowState::load($sid = _workflow_get_sid_by_items($items), $wid);
// @todo D8: remove below lines.
$entity = $this->entity;
$entity_type = $this->entity_type;
$entity_id = entity_id($entity_type, $entity);
if (!$entity) {
// No entity available, we are on the field Settings page - 'default value' field.
// This is hidden from the admin, because the default value can be different for every user.
} elseif (!$entity_id && $entity_type == 'comment') {
// Not possible: a comment on a non-existent node.
} elseif ($entity_id && $this->entity_type == 'comment') {
// This happens when we are on an entity's comment.
$referenced_entity_type = 'node';
// Comments only exist on nodes.
$referenced_entity = entity_load_single($referenced_entity_type, $entity_id);
// Comments only exist on nodes.
// Submit the data. $items is reset by reference to normal value, and is magically saved by the field itself.
$form = array();
$form_state = array();
$widget = new WorkflowDefaultWidget($this->field, $this->instance, $referenced_entity_type, $referenced_entity);
$widget->submit($form, $form_state, $items);
// $items is a proprietary D7 parameter.
// Remember: we are on a comment form, so the comment is saved automatically, but the referenced entity is not.
// @todo: probably we'd like to do this form within the Widget, but that does not know
// wether we are on a comment or a node form.
//
// Widget::submit() returns the new value in a 'sane' state.
// Save the referenced entity, but only is transition succeeded, and is not scheduled.
$old_sid = _workflow_get_sid_by_items($referenced_entity->{$field_name}['und']);
$new_sid = _workflow_get_sid_by_items($items);
if ($old_sid != $new_sid) {
$referenced_entity->{$field_name}['und'] = $items;
entity_save($referenced_entity_type, $referenced_entity);
}
} elseif ($this->entity_type != 'comment') {
if (isset($items[0]['value'])) {
// A 'normal' options.module-widget is used, and $items[0]['value'] is already properly set.
} elseif (isset($items[0]['workflow'])) {
// The WorkflowDefaultWidget is used.
// Submit the data. $items is reset by reference to normal value, and is magically saved by the field itself.
$form = array();
$form_state = array();
$widget = new WorkflowDefaultWidget($this->field, $this->instance, $entity_type, $entity);
$widget->submit($form, $form_state, $items);
// $items is a proprietary D7 parameter.
} else {
drupal_set_message('error in WorkfowItem->update()', 'error');
}
}
// A 'normal' node add page.
// We should not be here, since we only do inserts after $entity_id is known.
// $current_sid = Workflow::load($wid)->getCreationSid();
}
开发者ID:jhwestover,项目名称:opendata-portal,代码行数:70,代码来源:WorkflowItem.php
示例7: hook_uc_order_product_delete
/**
* Responds after order product deletion.
*
* This hook is invoked after the order product has been removed from the
* database.
*
* @param object $order_product
* The order product that is being deleted.
*
* @see hook_entity_delete()
* @see hook_uc_order_edit_form_product_remove()
*/
function hook_uc_order_product_delete(object $order_product)
{
db_delete('mytable')->condition('opid', entity_id('uc_order_product', $order_product))->execute();
}
开发者ID:sodacrackers,项目名称:washyacht,代码行数:16,代码来源:uc_order.api.php
示例8: submit
/**
* Implements workflow_transition() -> WorkflowDefaultWidget::submit().
*
* Overrides submit(array $form, array &$form_state).
* Contains 2 extra parameters for D7
*
* @param array $form
* @param array $form_state
* @param array $items
* The value of the field.
* @param bool $force
* TRUE if all access must be overridden, e.g., for Rules.
*
* @return int
* If update succeeded, the new State Id. Else, the old Id is returned.
*
* This is called from function _workflowfield_form_submit($form, &$form_state)
* It is a replacement of function workflow_transition($node, $new_sid, $force, $field)
* It performs the following actions;
* - save a scheduled action
* - update history
* - restore the normal $items for the field.
* @todo: remove update of {node_form} table. (separate task, because it has features, too)
*/
public function submit(array $form, array &$form_state, array &$items, $force = FALSE)
{
global $user;
// @todo #2287057: verify if submit() really is only used for UI. If not, $user must be passed.
$entity_type = $this->entity_type;
$entity = $this->entity;
$field_name = isset($this->field['field_name']) ? $this->field['field_name'] : '';
// Extract the data from $items, depending on the type of widget.
// @todo D8: use MassageFormValues($values, $form, $form_state).
$old_sid = workflow_node_previous_state($entity, $entity_type, $field_name);
if (!$old_sid) {
// At this moment, $old_sid should have a value. If the content does not
// have a state yet, old_sid contains '(creation)' state. But if the
// content is not associated to a workflow, old_sid is now 0. This may
// happen in workflow_vbo, if you assign a state to non-relevant nodes.
$entity_id = entity_id($entity_type, $entity);
drupal_set_message(t('Error: content !id has no workflow attached. The data is not saved.', array('!id' => $entity_id)), 'error');
// The new state is still the previous state.
$new_sid = $old_sid;
return $new_sid;
}
$transition = $this->getTransition($old_sid, $items, $field_name, $user);
$force = $force || $transition->isForced();
// Try to execute the transition. Return $old_sid when error.
if (!$transition) {
// This should only happen when testing/developing.
drupal_set_message(t('Error: the transition from %old_sid to %new_sid could not be generated.'), 'error');
// The current value is still the previous state.
$new_sid = $old_sid;
} elseif (!$transition->isScheduled()) {
// Now the data is captured in the Transition, and before calling the
// Execution, restore the default values for Workflow Field.
// For instance, workflow_rules evaluates this.
if ($field_name) {
// $items = array();
// $items[0]['value'] = $old_sid;
// $entity->{$field_name}[$transition->language] = $items;
}
// It's an immediate change. Do the transition.
// - validate option; add hook to let other modules change comment.
// - add to history; add to watchdog
// Return the new State ID. (Execution may fail and return the old Sid.)
$new_sid = $transition->execute($force);
} else {
// A scheduled transition must only be saved to the database.
// The entity is not changed.
$transition->save();
// The current value is still the previous state.
$new_sid = $old_sid;
}
// The entity is still to be saved, so set to a 'normal' value.
if ($field_name) {
$items = array();
$items[0]['value'] = $new_sid;
$entity->{$field_name}[$transition->language] = $items;
}
return $new_sid;
}
开发者ID:TabulaData,项目名称:donl_d7,代码行数:82,代码来源:WorkflowDefaultWidget.php
示例9: hook_rules_link_delete
/**
* Responds to rules link deletion.
*
* This hook is invoked after the rules link has been removed from the database.
*
* @param RulesLink $rules_link
* The rules link that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_rules_link_delete(RulesLink $rules_link)
{
db_delete('mytable')->condition('pid', entity_id('rules_link', $rules_link))->execute();
}
开发者ID:reveillette,项目名称:CEML,代码行数:14,代码来源:rules_link.api.php
示例10: hook_application_type_delete
/**
* Responds to application_type deletion.
*
* This hook is invoked after the application_type has been removed from the database.
*
* @param ApplicationType $application_type
* The application_type that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_application_type_delete(ApplicationType $application_type)
{
db_delete('mytable')->condition('pid', entity_id('application_type', $application_type))->execute();
}
开发者ID:NISR,项目名称:web_d7,代码行数:14,代码来源:application.api.php
示例11: hook_example_task_type_delete
/**
* Responds to example_task_type deletion.
*
* This hook is invoked after the example_task_type has been removed from the database.
*
* @param ExampleTaskType $example_task_type
* The example_task_type that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_example_task_type_delete(ExampleTaskType $example_task_type)
{
db_delete('mytable')->condition('pid', entity_id('example_task_type', $example_task_type))->execute();
}
开发者ID:drupalcrunch,项目名称:entity_workshop,代码行数:14,代码来源:example_task.api.php
示例12: hook_search_api_autocomplete_search_delete
/**
* Responds to search deletion.
*
* This hook is invoked after the search has been removed from the database.
*
* @param SearchApiAutocompleteSearch $search
* The search that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_search_api_autocomplete_search_delete(SearchApiAutocompleteSearch $search)
{
db_delete('mytable')->condition('pid', entity_id('search_api_autocomplete_search', $search))->execute();
}
开发者ID:billtzim,项目名称:Points-of-Interest,代码行数:14,代码来源:search_api_autocomplete.api.php
示例13: hook_datasource_type_delete
/**
* Responds to datasource_type deletion.
*
* This hook is invoked after the datasource_type has been removed from the database.
*
* @param DatasourceType $datasource_type
* The datasource_type that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_datasource_type_delete(DatasourceType $datasource_type)
{
db_delete('mytable')->condition('pid', entity_id('datasource_type', $datasource_type))->execute();
}
开发者ID:NISR,项目名称:web_d7,代码行数:14,代码来源:datasource.api.php
示例14: hook_publication_type_delete
/**
* Responds to publication_type deletion.
*
* This hook is invoked after the publication_type has been removed from the database.
*
* @param PublicationType $publication_type
* The publication_type that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_publication_type_delete(PublicationType $publication_type)
{
db_delete('mytable')->condition('pid', entity_id('publication_type', $publication_type))->execute();
}
开发者ID:NISR,项目名称:web_d7,代码行数:14,代码来源:publication.api.php
示例15: hook_openbadging_type_delete
/**
* Responds to openbadging_type deletion.
*
* This hook is invoked after the openbadging_type has been removed from the database.
*
* @param OpenbadgingEntityType $openbadging_type
* The openbadging_type that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_openbadging_type_delete(OpenbadgingEntityType $openbadging_type)
{
db_delete('mytable')->condition('pid', entity_id('openbadging_type', $openbadging_type))->execute();
}
开发者ID:galecia,项目名称:gra3,代码行数:14,代码来源:openbadging.api.php
示例16: hook_spotify_playlist_type_delete
/**
* Responds to spotify_playlist deletion.
*
* This hook is invoked after the spotify_playlist has been removed from the database.
*
* @param SpotifyPlaylist $spotify_playlist
* The spotify_playlist that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_spotify_playlist_type_delete(SpotifyPlaylist $spotify_playlist)
{
db_delete('mytable')->condition('pid', entity_id('spotify_playlist', $spotify_playlist))->execute();
}
开发者ID:jobjol,项目名称:spotify-playlist,代码行数:14,代码来源:spotify_playlist.api.php
示例17: hook_search_api_saved_search_settings_delete
/**
* Responds to settings entity deletion.
*
* This hook is invoked after the settings entity has been removed from the
* database.
*
* @param SearchApiSavedSearchSettings $settings
* The settings entity that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_search_api_saved_search_settings_delete(SearchApiSavedSearchSettings $settings)
{
db_delete('mytable')->condition('pid', entity_id('search_api_saved_search_settings', $settings))->execute();
}
开发者ID:drupalconnect,项目名称:finsearches,代码行数:15,代码来源:search_api_saved_searches.api.php
示例18: delete
/**
* Implements hook_field_delete() -> FieldItemInterface::delete().
*/
public function delete($items)
{
global $user;
$entity_type = $this->entity_type;
$entity = $this->entity;
$entity_id = entity_id($entity_type, $entity);
$field_name = $this->field['field_name'];
// Delete the record in {workflow_node} - not for Workflow Field.
// Use a one-liner for better code analysis when grepping on old code.
!$field_name ? workflow_delete_workflow_node_by_nid($entity_id) : NULL;
// Add a history record in {workflow_node_history}.
// @see drupal.org/node/2165349, comment by Bastlynn:
// The reason for this history log upon delete is because Workflow module
// has historically been used to track node states and accountability in
// business environments where accountability for changes over time is
// *absolutely* required. Think banking and/or particularly strict
// retention policies for legal reasons.
//
// However, a deleted nid may be re-used under certain circumstances:
// e.g., working with InnoDB or after restart the DB server.
// This may cause that old history is associated with a new node.
$old_sid = _workflow_get_sid_by_items($items);
$new_sid = (int) WORKFLOW_DELETION;
$comment = t('Entity deleted.');
$transition = new WorkflowTransition();
$transition->setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $user->uid, REQUEST_TIME, $comment);
$transition->save();
// Delete all records for this node in {workflow_scheduled_transition}.
foreach (WorkflowScheduledTransition::load($entity_type, $entity_id, $field_name) as $scheduled_transition) {
$scheduled_transition->delete();
}
}
开发者ID:charx0r,项目名称:time,代码行数:35,代码来源:WorkflowItem.php
示例19: 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;
}
开发者ID:jhwestover,项目名称:opendata-portal,代码行数:60,代码来源:WorkflowState.php
示例20: getOptions
/**
* Returns the allowed values for the current state.
*
* @param string $entity_type
* The type of the entity at hand.
* @param object $entity
* The entity at hand. May be NULL (E.g., on a Field settings page).
* @param $field_name
* @param $user
* @param bool $force
*
* @return array
* An array of sid=>label pairs.
* If $this->sid is set, returns the allowed transitions from this state.
* If $this->sid is 0 or FALSE, then labels of ALL states of the State's
* Workflow are returned.
*
* D7.x-2.x: deprecated workflow_field_choices() --> WorkflowState->getOptions()
*/
public function getOptions($entity_type, $entity, $field_name, $user, $force = FALSE)
{
// Define an Entity-specific cache per page load.
static $cache = array();
$options = array();
$entity_id = $entity ? entity_id($entity_type, $entity) : '';
$current_sid = $this->sid;
// Get options from page cache, using a non-empty index (just to be sure).
$entity_index = !$entity ? 'x' : $entity_id;
if (isset($cache[$entity_type][$entity_index][$force][$current_sid])) {
$options = $cache[$entity_type][$entity_index][$force][$current_sid];
return $options;
}
$workflow = $this->getWorkflow();
if (!$workflow) {
// No workflow, no options ;-)
} elseif (!$current_sid) {
// If no State ID is given, we return all states.
// We cannot use getTransitions, since there are no ConfigTransitions
// from State with ID 0, and we do not want to repeat States.
foreach ($workflow->getStates() as $state) {
$options[$state->value()] = $state->label();
// Translation is done later.
}
} else {
/* @var $transition WorkflowTransition */
$transitions = $this->getTransitions($entity_type, $entity, $field_name, $user, $force);
foreach ($transitions as $transition) {
// Get the label of the transition, and if empty of the target state.
// Beware: the target state may not exist, since it can be invented
// by custom code in the above drupal_alter() hook.
if (!($label = $transition->label())) {
$target_state = $transition->getNewState();
$label = $target_state ? $target_state->label() : '';
}
$new_sid = $transition->target_sid;
$options[$new_sid] = $label;
// Translation is done later.
}
// Include current state for same-state transitions, except when $sid = 0.
// Caveat: this unnecessary since 7.x-2.3 (where stay-on-state transitions are saved, too.)
// but only if the transitions have been saved at least one time.
if ($current_sid && $current_sid != $workflow->getCreationSid()) {
if (!isset($options[$current_sid])) {
$options[$current_sid] = $this->label();
// Translation is done later.
}
}
// Properly fix the labels.
// Translate, convert '&', make secure.
foreach ($options as $key => $label) {
$options[$key] = html_entity_decode(check_plain(t($label)));
}
// Save to entity-specific cache.
$cache[$entity_type][$entity_index][$force][$current_sid] = $options;
}
return $options;
}
开发者ID:Loudon-Company,项目名称:LacunaStories,代码行数:77,代码来源:WorkflowState.php
注:本文中的entity_id函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论