本文整理汇总了PHP中entity_extract_ids函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_extract_ids函数的具体用法?PHP entity_extract_ids怎么用?PHP entity_extract_ids使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_extract_ids函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewAction
/**
* @Route("/{entity_type}/{entity}", name="entity_view", defaults={"view_mode" = "full", "langcode" = null, "page" = null})
* @Method("GET")
* @ParamConverter("entity", converter="drupal.entity")
* @Template
*/
public function viewAction(Request $request, $entity_type, $entity)
{
$view_mode = $request->get('view_mode');
$langcode = $request->get('langcode');
$page = $request->get('page');
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
$entities = entity_view($entity_type, array($id => $entity), $view_mode, $langcode, $page);
return array('label' => entity_label($entity_type, $entity), 'uri' => entity_uri($entity_type, $entity), 'entity_type' => $entity_type, 'id' => $id, 'vid' => $vid, 'bundle' => $bundle, 'entity' => $entity, 'content' => reset($entities[$entity_type]));
}
示例2: entity_allows_revisions
/**
* Determine if the entity allows revisions.
*/
public function entity_allows_revisions($entity)
{
$retval = array();
list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
$node_options = variable_get('node_options_' . $bundle, array('status', 'promote'));
$retval[0] = in_array('revision', $node_options);
$retval[1] = user_access('administer nodes');
return $retval;
}
示例3: __construct
/**
* Constructor
*
* @param string $eventName
* @param string $entityType
* @param EntityInterface $entity
* @param int $userId
* @param array $arguments
*/
public function __construct($eventName, $entityType, EntityInterface $entity, $userId = null, array $arguments = [])
{
$this->setEventName($eventName);
$this->setEntityType($entityType);
$this->setUserId($userId);
list($id, , $bundle) = entity_extract_ids($entityType, $entity);
// Keeping the 'uid' in arguments allows compatibility with the
// makinacorpus/apubsub API, using subject too
parent::__construct($entity, $arguments + ['uid' => $userId, 'id' => $id, 'bundle' => $bundle]);
}
示例4: generate
/**
* Implements EditMetadataGeneratorInterface::generate().
*/
public function generate($entity_type, $entity, array $instance, $langcode, $view_mode)
{
$field_name = $instance['field_name'];
// Early-return if user does not have access.
$access = $this->accessChecker->accessEditEntityField($entity_type, $entity, $field_name);
if (!$access) {
return array('access' => FALSE);
}
// Early-return if no editor is available.
if (!_edit_is_extra_field($entity_type, $field_name)) {
$display = field_get_display($instance, $view_mode, $entity);
$formatter_type = field_info_formatter_types($display['type']);
$items = field_get_items($entity_type, $entity, $field_name, $langcode);
$items = $items === FALSE ? array() : $items;
$editor_id = $this->editorSelector->getEditor($formatter_type, $instance, $items);
} else {
// @see hook_edit_extra_fields_info()
$extra = edit_extra_field_info($entity_type, $field_name);
if (isset($extra['view mode dependent editor'][$view_mode])) {
$editor_id = $extra['view mode dependent editor'][$view_mode];
} else {
$editor_id = $extra['default editor'];
}
}
if (!isset($editor_id)) {
return array('access' => FALSE);
}
// Gather metadata, allow the editor to add additional metadata of its own.
if (!_edit_is_extra_field($entity_type, $field_name)) {
$label = $instance['label'];
} else {
$label = edit_extra_field_info($entity_type, $field_name, 'label');
}
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
$metadata = array('label' => check_plain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity_type, '@id' => $id, '@field' => $label)));
if (!_edit_is_extra_field($entity_type, $field_name)) {
$editor = edit_editor_get($editor_id);
if (!empty($editor['metadata callback'])) {
if ($editor['file']) {
require_once $editor['file path'] . '/' . $editor['file'];
}
if (function_exists($editor['metadata callback'])) {
$custom_metadata = $editor['metadata callback']($instance, $items);
if (count($custom_metadata)) {
$metadata['custom'] = $custom_metadata;
}
}
}
// Allow the metadata to be altered.
$context = array('entity_type' => $entity_type, 'entity' => $entity, 'field' => $instance, 'items' => $items);
drupal_alter('edit_editor_metadata', $metadata, $editor_id, $context);
}
return $metadata;
}
示例5: hook_linked_field_settings_alter
/**
* Act on Linked Field settings
*
* This hook is invoked from linked_field_field_attach_view_alter() when linking
* a field. It allows you to override all settings.
*
* @param $settings
* An associative array of Linked Field settings.
* @param $context
* An associative array containing:
* - entity_type: The type of $entity; for example, 'node' or 'user'.
* - entity: The entity with fields to render.
* - view_mode: View mode; for example, 'full' or 'teaser'.
* - display: Either a view mode string or an array of display settings. If
* this hook is being invoked from field_attach_view(), the 'display'
* element is set to the view mode string. If this hook is being invoked
* from field_view_field(), this element is set to the $display argument
* and the view_mode element is set to '_custom'. See field_view_field()
* for more information on what its $display argument contains.
* - language: The language code used for rendering.
*/
function hook_linked_field_settings_alter(&$settings, $context)
{
$entity_type = $context['entity_type'];
$entity = $context['entity'];
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$view_mode = $context['view_mode'];
// Add custom attribute for the link.
if ($entity_type == 'node' && $bundle == 'article' && $view_mode == 'default') {
$settings['options']['attributes']['data-id'] = $entity->nid;
}
}
示例6: entity_allows_revisions
/**
* Determine if the entity allows revisions.
*/
public function entity_allows_revisions($entity)
{
$retval = array();
list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
$node_options = variable_get('node_options_' . $bundle, array('status', 'promote'));
// Whether or not the entity supports revisions.
$retval[0] = TRUE;
// Whether or not the user can control if a revision is created.
$retval[1] = user_access('administer nodes');
// Whether or not the revision is created by default.
$retval[2] = in_array('revision', $node_options);
return $retval;
}
示例7: buildListCache
/**
* Prepare internal bundle and id list cache
*/
private function buildListCache()
{
if (null !== $this->idList) {
return;
}
foreach ($this->subject as $entity) {
list($id, , $bundle) = entity_extract_ids($this->getEntityType(), $entity);
$this->idList[] = $id;
$this->bundleList[$id] = $bundle;
$this->bundleList = $bundle;
$this->bundleList = array_unique($this->bundleList);
}
}
示例8: entityFormSubmit
/**
* Overrides EntityInlineEntityFormController::entityFormSubmit().
*
* Fixes some of the custom entity values, similar to
* fieldable_panels_panes_entity_edit_form_submit().
*/
public function entityFormSubmit(&$entity_form, &$form_state)
{
$info = entity_get_info($this->entityType);
list(, , $bundle) = entity_extract_ids($this->entityType, $entity_form['#entity']);
$entity = $entity_form['#entity'];
$entity_values = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);
// Some additional adjustments necessary for FPP to save correctly.
if (!empty($entity_values['link']['path'])) {
$entity_values['path'] = $entity_values['link']['path'];
}
if (isset($entity_values['link']['link'])) {
$entity_values['link'] = $entity_values['link']['link'];
} else {
$entity_values['link'] = 0;
}
// The 'reusable' option contains several sub fields.
if (isset($entity_values['reusable']['reusable'])) {
$reusable = $entity_values['reusable'];
$entity_values['reusable'] = FALSE;
$entity_values['category'] = '';
$entity_values['admin_title'] = '';
$entity_values['admin_description'] = '';
foreach (array('reusable', 'category', 'admin_title', 'admin_description') as $field) {
if (isset($reusable[$field])) {
$entity_values[$field] = $reusable[$field];
}
}
}
// Only fix the revision log if a revision is being saved.
$entity_values['log'] = '';
if (isset($entity_values['revision']['revision'])) {
if (isset($entity_values['revision']['log'])) {
$entity_values['log'] = $entity_values['revision']['log'];
}
$entity_values['revision'] = $entity_values['revision']['revision'];
} else {
$entity_values['revision'] = 0;
}
// Copy top-level form values that are not for fields to entity properties,
// without changing existing entity properties that are not being edited by
// this form. Copying field values must be done using field_attach_submit().
$values_excluding_fields = $info['fieldable'] ? array_diff_key($entity_values, field_info_instances($this->entityType, $bundle)) : $entity_values;
foreach ($values_excluding_fields as $key => $value) {
$entity->{$key} = $value;
}
if ($info['fieldable']) {
field_attach_submit($this->entityType, $entity, $entity_form, $form_state);
}
}
开发者ID:michael-wojcik,项目名称:open_eggheads,代码行数:55,代码来源:FieldablePanelsPaneInlineEntityFormController.class.php
示例9: load
/**
* Implements EntityReference_BehaviorHandler_Abstract::load().
*/
public function load($entity_type, $entities, $field, $instances, $langcode, &$items)
{
// Get the OG memberships from the field.
$field_name = $field['field_name'];
$target_type = $field['settings']['target_type'];
foreach ($entities as $entity) {
list($id) = entity_extract_ids($entity_type, $entity);
$items[$id] = array();
$gids = og_get_entity_groups($entity_type, $entity, array(), $field_name);
if (empty($gids[$target_type])) {
continue;
}
foreach ($gids[$target_type] as $gid) {
$items[$id][] = array('target_id' => $gid);
}
}
}
示例10: update
/**
*
* Do the actual update - passes the update to the plugin's process functions
*/
function update()
{
if (function_exists($this->plugin['process'])) {
$this->plugin['process']($this);
}
// Are there any form errors?
if ($errors = form_get_errors()) {
foreach ($errors as $error) {
// Form errors will apply for all entities
foreach ($this->entities as $entity) {
list($id) = entity_extract_ids($this->entity_type, $entity);
$this->set_error($id, $error);
}
}
}
return $this->get_result();
}
示例11: entityForm
/**
* Overrides EntityInlineEntityFormController::entityForm().
*
* Copied from fieldable_panels_panes_entity_edit_form().
*/
public function entityForm($entity_form, &$form_state)
{
// Make the other form items dependent upon it.
ctools_include('dependent');
ctools_add_js('dependent');
$entity = $entity_form['#entity'];
$entity_type = 'fieldable_panels_pane';
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
// Map these properties for entity translations.
$entity_form['#entity_type'] = array('#type' => 'value', '#value' => $entity->bundle);
$form_state['fieldable_panels_pane'] = $entity_form['#entity'];
$entity_form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $entity->title, '#weight' => -10);
$entity_form['language'] = array('#type' => 'value', '#value' => $entity->language);
$entity_form['link'] = array('#weight' => -10);
$entity_form['link']['link'] = array('#title' => t('Make title a link'), '#type' => 'checkbox', '#default_value' => $entity->link, '#description' => t('Check here to make the title link to another page.'), '#id' => 'edit-link');
$entity_form['link']['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#description' => t('The path for this link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), '#dependency' => array('edit-link' => array(1)), '#default_value' => $entity->path);
$entity_form['reusable'] = array('#weight' => 10);
$entity_form['revision'] = array('#weight' => 11);
if (empty($entity->fpid)) {
$entity_form['revision']['#access'] = FALSE;
}
$entity_form['reusable']['reusable'] = array('#type' => 'checkbox', '#title' => t('Make this entity reusable'), '#default_value' => $entity->reusable, '#id' => 'edit-reusable');
$entity_form['reusable']['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#description' => t('The category this content will appear in the "Add content" modal. If left blank the category will be "Miscellaneous".'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->category);
$entity_form['reusable']['admin_title'] = array('#type' => 'textfield', '#title' => t('Administrative title'), '#description' => t('The name this content will appear in the "Add content" modal.'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->admin_title);
$entity_form['reusable']['admin_description'] = array('#type' => 'textarea', '#title' => t('Administrative description'), '#description' => t('A description of what this content is, does or is for, for administrative use.'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->admin_description);
$entity_form['revision']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => 1, '#id' => 'edit-revision');
if (!user_access('administer fieldable panels panes') || empty($entity->fpid) || $entity->vid != $entity->current_vid) {
$form['revision']['revision']['#disabled'] = TRUE;
$form['revision']['revision']['#value'] = TRUE;
}
$entity_form['revision']['log'] = array('#type' => 'textarea', '#title' => t('Log message'), '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'), '#dependency' => array('edit-revision' => array(1)), '#default_value' => '');
$langcode = entity_language('fieldable_panels_pane', $entity);
field_attach_form('fieldable_panels_pane', $entity, $entity_form, $form_state, $langcode);
// _field_extra_fields_pre_render() doesn't execute properly, so manually
// set the weights.
$extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');
foreach ($extra_fields as $name => $settings) {
if (isset($entity_form[$name])) {
$entity_form[$name]['#weight'] = $settings['weight'];
}
}
return $entity_form;
}
示例12: getList
/**
* Overrides RestfulEntityBase::getList().
*/
public function getList() {
$entity_type = $this->entityType;
$result = $this
->getQueryForList()
->execute();
if (empty($result[$entity_type])) {
return;
}
$account = $this->getAccount();
$request = $this->getRequest();
$ids = array_keys($result[$entity_type]);
// Pre-load all entities.
$entities = entity_load($entity_type, $ids);
$return = array();
$handlers = array();
$resources_info = $this->getBundles();
foreach ($entities as $entity) {
// Call each handler by its registered bundle.
list($id,, $bundle) = entity_extract_ids($this->getEntityType(), $entity);
if (empty($handlers[$bundle])) {
$version = $this->getVersion();
$handlers[$bundle] = restful_get_restful_handler($resources_info[$bundle], $version['major'], $version['minor']);
}
$bundle_handler = $handlers[$bundle];
$bundle_handler->setAccount($account);
$bundle_handler->setRequest($request);
$return[] = $bundle_handler->viewEntity($id);
}
return $return;
}
示例13: getReferencableEntities
/**
* Implements EntityReferenceHandler::getReferencableEntities().
*/
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0)
{
global $user;
// For admin users, use the standard plugin behavior.
if (user_access('assign content ownership')) {
return parent::getReferencableEntities($match, $match_operator, $limit);
}
$options = array();
if (empty($user->uid)) {
return $options;
}
$uids = array($user->uid);
if (function_exists('yaffle_delegation_get_delegate_uids')) {
$uids += yaffle_delegation_get_delegate_uids($user->uid);
}
$entities = entity_load($entity_type, array_keys($results[$entity_type]));
foreach ($entities as $entity_id => $entity) {
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$options[$bundle][$entity_id] = check_plain($this->getLabel($entity));
}
// $uids = array($user->uid);
// $options = array();
// $entity_type = $this->field['settings']['target_type'];
// $query = $this->buildEntityFieldQuery($match, $match_operator);
// if ($limit > 0) {
// $query->range(0, $limit);
// }
// $results = $query->execute();
// if (!empty($results[$entity_type])) {
// $entities = entity_load($entity_type, array_keys($results[$entity_type]));
// foreach ($entities as $entity_id => $entity) {
// list(,, $bundle) = entity_extract_ids($entity_type, $entity);
// $options[$bundle][$entity_id] = check_plain($this->getLabel($entity));
// }
// }
return $options;
}
示例14: hook_form_alter
/**
* Implements hook_form_alter().
*
* Use this hook to alter the form on a Node Form, Comment Form (Edit page).
*/
function hook_form_alter(&$form, $form_state, $form_id)
{
// Get the Entity.
$entity = $form['#entity'];
$entity_type = $form['#entity_type'];
// Use the complicated form, which is suited for all Entity Types.
list(, , $entity_bundle) = entity_extract_ids($entity_type, $entity);
// Discover if this is the correct form.
// ...
// Get the current state and act upon it.
// .. copy code from the hook above.
}
示例15: hook_field_storage_purge
/**
* Remove field storage information when field data is purged.
*
* Called from field_purge_data() to allow the field storage
* module to delete field data information.
*
* @param $entity_type
* The type of $entity; for example, 'node' or 'user'.
* @param $entity
* The pseudo-entity whose field data to delete.
* @param $field
* The (possibly deleted) field whose data is being purged.
* @param $instance
* The deleted field instance whose data is being purged.
*/
function hook_field_storage_purge($entity_type, $entity, $field, $instance)
{
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
$table_name = _field_sql_storage_tablename($field);
$revision_name = _field_sql_storage_revision_tablename($field);
db_delete($table_name)->condition('entity_type', $entity_type)->condition('entity_id', $id)->execute();
db_delete($revision_name)->condition('entity_type', $entity_type)->condition('entity_id', $id)->execute();
}