本文整理汇总了PHP中entity_id函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_id函数的具体用法?PHP entity_id怎么用?PHP entity_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}