public function views_data_alter(&$data, $field)
 {
     $entity_info = entity_get_info($field['settings']['target_type']);
     $field_name = $field['field_name'] . '_target_id';
     foreach ($data as $table_name => &$table_data) {
         if (isset($table_data[$field_name])) {
             // This doesn't clash with reference_option_limit module, because that
             // never got round to getting support for Views with entityreference
             // fields.
             $limit_option_pseudo_field_name = $field_name . '_option_limit';
             $data[$table_name][$limit_option_pseudo_field_name] = array();
             // Copy properties from the original.
             foreach (array('group', 'title', 'title short', 'help') as $key) {
                 $data[$table_name][$limit_option_pseudo_field_name][$key] = $table_data[$field_name][$key];
             }
             $data[$table_name][$limit_option_pseudo_field_name]['title'] .= ' ' . t('(with restricted options)');
             $data[$table_name][$limit_option_pseudo_field_name]['filter'] = array();
             // Copy properties from the original filter definition.
             foreach (array('field', 'table', 'field_name', 'additional fields') as $key) {
                 $data[$table_name][$limit_option_pseudo_field_name]['filter'][$key] = $table_data[$field_name]['filter'][$key];
             }
             $data[$table_name][$limit_option_pseudo_field_name]['filter']['handler'] = 'views_filter_option_limit_handler_filter_options_limit';
         }
     }
 }
 /**
  * Implements EntityReferenceHandler::settingsForm().
  */
 public static function settingsForm($field, $instance)
 {
     $view_settings = empty($field['settings']['handler_settings']['view']) ? '' : $field['settings']['handler_settings']['view'];
     $displays = views_get_applicable_views('entityreference display');
     // Filter views that list the entity type we want, and group the separate
     // displays by view.
     $entity_info = entity_get_info($field['settings']['target_type']);
     $options = array();
     foreach ($displays as $data) {
         list($view, $display_id) = $data;
         if ($view->base_table == $entity_info['base table']) {
             $options[$view->name . ':' . $display_id] = $view->name . ' - ' . $view->display[$display_id]->display_title;
         }
     }
     // The value of the 'view_and_display' select below will need to be split
     // into 'view_name' and 'view_display' in the final submitted values, so
     // we massage the data at validate time on the wrapping element (not
     // ideal).
     $form['view']['#element_validate'] = array('entityreference_view_settings_validate');
     if ($options) {
         $default = !empty($view_settings['view_name']) ? $view_settings['view_name'] . ':' . $view_settings['display_name'] : NULL;
         $form['view']['view_and_display'] = array('#type' => 'select', '#title' => t('View used to select the entities'), '#required' => TRUE, '#options' => $options, '#default_value' => $default, '#description' => '<p>' . t('Choose the view and display that select the entities that can be referenced.<br />Only views with a display of type "Entity Reference" are eligible.') . '</p>');
         $default = !empty($view_settings['args']) ? implode(', ', $view_settings['args']) : '';
         $form['view']['args'] = array('#type' => 'textfield', '#title' => t('View arguments'), '#default_value' => $default, '#required' => FALSE, '#description' => t('Provide a comma separated list of arguments to pass to the view.'));
     } else {
         $form['view']['no_view_help'] = array('#markup' => '<p>' . t('No eligible views were found. <a href="@create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href="@existing">existing view</a>.', array('@create' => url('admin/structure/views/add'), '@existing' => url('admin/structure/views'))) . '</p>');
     }
     return $form;
 }
 /**
  * Builds extra settings for the block edit form.
  */
 public function form($bean, $form, &$form_state)
 {
     // Here we are defining the form.
     $form = array();
     // Select objects for the vocabularies that will be used.
     $vocabulary = taxonomy_get_vocabularies();
     $select_vocabulary_array = array();
     foreach ($vocabulary as $item) {
         $select_vocabulary_array[$item->machine_name] = $item->name;
     }
     // Building the basic form for individual 'related' bean configuration.
     $form['filters'] = array('#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Filters'));
     // Determine related taxonomy term vocabularies.
     $form['filters']['vocabulary'] = array('#type' => 'select', '#title' => t('Vocabulary'), '#options' => $select_vocabulary_array, '#default_value' => $bean->filters['vocabulary'], '#required' => TRUE, '#multiple' => TRUE, '#size' => 5);
     // Settings fieldset is used for configuring the 'listing' bean output.
     $form['settings'] = array('#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Output'));
     // Select objects for the taxonomy term view modes that will be used.
     $term_view_modes = array();
     $entity_info = entity_get_info();
     foreach ($entity_info['taxonomy_term']['view modes'] as $key => $value) {
         $term_view_modes[$key] = $value['label'];
     }
     // User select which view mode to use for the term listing inside the bean.
     $form['settings']['term_view_mode'] = array('#type' => 'select', '#title' => t('Taxonomy Term View Mode'), '#options' => $term_view_modes, '#default_value' => $bean->settings['term_view_mode'], '#required' => TRUE, '#multiple' => FALSE);
     // User define a maximum number of terms to be shown.
     $form['settings']['records_shown'] = array('#type' => 'textfield', '#title' => t('Records shown'), '#size' => 5, '#default_value' => $bean->settings['records_shown'], '#element_validate' => array('bean_tax_setting_is_numeric'));
     $form['settings']['hide_empty'] = array('#type' => 'checkbox', '#title' => t('Do not display block if there are no results.'), '#default_value' => $bean->settings['hide_empty']);
     return $form;
 }
 /**
  * Implements EntityReferenceHandler::getReferencableEntities().
  *
  * Completely bypass buildEntityFieldQuery(), as we want a regular SQL query
  * in order to group and order the timeslots by their containing schedules.
  */
 public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 25)
 {
     // We also come here when getting entities for the default value widget.
     // There's no way to check this is what we're doing so just return nothing
     // if the settings are missing.
     if (empty($this->field['settings']['handler_settings']['behaviors']['session_timeslot']['status'])) {
         return array();
     }
     // Figure out which fields are on schedules and point to timeslots.
     $timetable_set = timetable_get_timetable_set($this->field);
     $schedule_timeslot_field_name = $timetable_set['schedule']['field_name'];
     $schedule_entity_type = $timetable_set['schedule']['entity_type'];
     // Get details about the schedule entity type for the query.
     $schedule_entity_info = entity_get_info($schedule_entity_type);
     $schedule_entity_base_table = $schedule_entity_info['base table'];
     $schedule_entity_id_key = $schedule_entity_info['entity keys']['id'];
     $schedule_entity_label_key = $schedule_entity_info['entity keys']['label'];
     $results = db_query("SELECT\n      ts.id,\n      time.field_timeslot_time_value AS timeslot_value,\n      time.field_timeslot_time_value2 AS timeslot_value2,\n      schedule.{$schedule_entity_label_key} AS schedule_label\n      FROM {eck_timeslot} ts\n      JOIN {field_data_field_timeslot_time} time\n        ON ts.id = time.entity_id\n      JOIN {field_data_{$schedule_timeslot_field_name}} sts\n        ON ts.id = sts.{$schedule_timeslot_field_name}_target_id\n      JOIN {{$schedule_entity_base_table}} schedule\n        ON sts.entity_id = schedule.{$schedule_entity_id_key}\n      ")->fetchAllAssoc('id', PDO::FETCH_ASSOC);
     // TODO: get this from the field instance so we match whatever format the
     // site builder wants.
     $timefield_display_format = array('hour' => 'G', 'minute' => 'i', 'separator' => ':', 'period' => 'none', 'period_separator' => '');
     $timeslot_options = array();
     foreach ($results as $timeslot_id => $timeslot_data) {
         $timeslot_options[$timeslot_id] = check_plain($timeslot_data['schedule_label']) . ': ' . timefield_integer_to_time($timefield_display_format, $timeslot_data['timeslot_value']) . '-' . timefield_integer_to_time($timefield_display_format, $timeslot_data['timeslot_value2']);
     }
     $options = array('timeslot' => $timeslot_options);
     return $options;
 }
 /**
  * Build an EntityFieldQuery to get referencable entities.
  * Almost the same as EntityReference_SelectionHandler_Generic::buildEntityFieldQuery,
  * but the bundles are dynamic.
  */
 protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', $this->field['settings']['target_type']);
     $node_types = project_node_types_by_behavior($this->field['settings']['handler_settings']['behavior']);
     if (!empty($node_types)) {
         $query->entityCondition('bundle', $node_types, 'IN');
     }
     if (isset($match)) {
         $entity_info = entity_get_info($this->field['settings']['target_type']);
         if (isset($entity_info['entity keys']['label'])) {
             $query->propertyCondition($entity_info['entity keys']['label'], $match, $match_operator);
         }
     }
     // Add a generic entity access tag to the query.
     $query->addTag($this->field['settings']['target_type'] . '_access');
     $query->addTag('entityreference');
     $query->addMetaData('field', $this->field);
     $query->addMetaData('entityreference_selection_handler', $this);
     // Add the sort option.
     if (!empty($this->field['settings']['handler_settings']['sort'])) {
         $sort_settings = $this->field['settings']['handler_settings']['sort'];
         if ($sort_settings['type'] == 'property') {
             $query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']);
         } elseif ($sort_settings['type'] == 'field') {
             list($field, $column) = explode(':', $sort_settings['field'], 2);
             $query->fieldOrderBy($field, $column, $sort_settings['direction']);
         }
     }
     return $query;
 }
 /**
  * @see LdapAuthorizationConsumerAbstract::createConsumer
  */
 public function createConsumer($consumer_id, $consumer)
 {
     list($entity_type, $group_name, $rid) = explode(':', $consumer_id);
     $group = @ldap_authorization_og2_get_group_from_name($entity_type, $group_name);
     if ($group) {
         return FALSE;
     }
     // create og group with name of $group_name of entity type $entity_type
     $entity_info = entity_get_info($entity_type);
     $new_group_created = FALSE;
     /**
      *
      * @todo
      * need to create new entity with title of $group_name here
      *
      */
     if ($new_group_created === FALSE) {
         // if role is not created, remove from array to user object doesn't have it stored as granted
         watchdog('user', 'failed to create og group %group_name in ldap_authorizations module', array('%group_name' => $group_name));
         return FALSE;
     } else {
         watchdog('user', 'created  og group %group_name in ldap_authorizations module', array('%group_name' => $group_name));
     }
     return TRUE;
 }
 /**
  * Builds extra settings for the block edit form.
  */
 public function form($bean, $form, &$form_state)
 {
     // Here we are defining the form.
     $form = array();
     // Settings fieldset is used for configuring the 'related' bean output.
     $form['settings'] = array('#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Output'), '#prefix' => '<div id="output-wrapper">', '#suffix' => '</div>');
     // Instantiate entity info.
     $entity_info = entity_get_info();
     // Create a list of entity types that have view modes.
     $entity_types = array();
     foreach ($entity_info as $key => $value) {
         if (!empty($value['view modes'])) {
             $entity_types[$key] = $value['label'];
         }
     }
     // Set a cache duration for the block.
     $form['settings']['cache_duration'] = array('#type' => 'textfield', '#title' => t('Cache duration (in minutes)'), '#size' => 5, '#default_value' => $bean->settings['cache_duration'], '#required' => TRUE);
     // User select how entites are related.
     $form['settings']['related'] = array('#type' => 'select', '#title' => t('Related To'), '#options' => array('page' => 'Active Page', 'user' => 'Logged-in User'), '#default_value' => $bean->settings['related'], '#required' => TRUE, '#multiple' => FALSE);
     // Determine if auth-user caching is appropriate.
     $form['settings']['cache_auth_user'] = array('#type' => 'checkbox', '#title' => t('Cache this block for authenticated users.'), '#description' => t('Warning: This will create a cache record for every authenticated user that views this block.'), '#default_value' => $bean->settings['cache_auth_user'], '#states' => array('visible' => array(':input[name="settings[related]"]' => array('value' => 'user'))));
     // Determine if anon-user caching is appropriate.
     $form['settings']['cache_anon_user'] = array('#type' => 'checkbox', '#title' => t('Cache this block for anonymous users.'), '#description' => t('This will create a cache record for anonymous users that view this block.'), '#default_value' => $bean->settings['cache_anon_user'], '#states' => array('visible' => array(':input[name="settings[related]"]' => array('value' => 'user'))));
     // User select which entity type to use for output.
     $form['settings']['entity_type'] = array('#type' => 'select', '#title' => t('Entity Type'), '#options' => $entity_types, '#default_value' => $bean->settings['entity_type'], '#required' => TRUE, '#multiple' => FALSE, '#ajax' => array('callback' => 'bean_tax_entity_type_callback', 'wrapper' => 'output-wrapper', 'method' => 'replace'));
     // Check for an ajax update and use new entity_type setting.
     if (!isset($form_state['values']['settings']['entity_type'])) {
         $entity_type = $bean->settings['entity_type'];
     } else {
         $entity_type = $form_state['values']['settings']['entity_type'];
     }
     // User select which view mode to use for the results inside the bean.
     $form['settings']['entity_view_mode'] = array('#type' => 'select', '#title' => t('Entity View Mode'), '#options' => bean_tax_get_entity_view_modes($entity_info, $entity_type), '#default_value' => $bean->settings['entity_view_mode'], '#required' => TRUE, '#multiple' => FALSE);
     // Determine what entity bundle types to display.
     $form['settings']['bundle_types'] = array('#type' => 'select', '#title' => t('Entity Bundles'), '#options' => bean_tax_get_entity_bundles($entity_type), '#default_value' => $bean->settings['bundle_types'], '#required' => TRUE, '#multiple' => TRUE, '#size' => 5);
     $form['settings']['hide_empty'] = array('#type' => 'checkbox', '#title' => t('Do not display block if there are no results.'), '#default_value' => $bean->settings['hide_empty']);
     $form['settings']['unmatch_add'] = array('#type' => 'checkbox', '#title' => t('Append unrelated entities so there are more results.'), '#default_value' => $bean->settings['unmatch_add']);
     // Select objects for the vocabularies that will be used.
     $vocabulary = taxonomy_get_vocabularies();
     $select_vocabulary_array = array();
     foreach ($vocabulary as $item) {
         $select_vocabulary_array[$item->machine_name] = $item->name;
     }
     // Define the filters fieldset.
     $form['filters'] = array('#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Filters'));
     // User define a maximum number of entities to be shown.
     $form['filters']['records_shown'] = array('#type' => 'textfield', '#title' => t('Records shown'), '#size' => 5, '#default_value' => $bean->filters['records_shown'], '#element_validate' => array('bean_tax_setting_is_numeric'));
     // User define a maximum number of entities to be shown.
     $form['filters']['offset_results'] = array('#type' => 'textfield', '#title' => t('Offset Results'), '#size' => 5, '#default_value' => $bean->filters['offset_results'], '#element_validate' => array('bean_tax_setting_is_numeric'));
     // Determine related taxonomy term vocabularies.
     $form['filters']['vocabulary'] = array('#type' => 'select', '#title' => t('Vocabularies'), '#options' => $select_vocabulary_array, '#default_value' => $bean->filters['vocabulary'], '#required' => TRUE, '#multiple' => TRUE, '#size' => 5);
     // Define a "read more" style link to be shown at the bottom of the bean.
     $form['more_link'] = array('#type' => 'fieldset', '#tree' => TRUE, '#title' => t('More link'));
     // Link text shown on the 'more link' to be defined by user.
     $form['more_link']['text'] = array('#type' => 'textfield', '#title' => t('Link text'), '#default_value' => $bean->more_link['text']);
     // Actual URL path for the 'more link' defined by user.
     $form['more_link']['path'] = array('#type' => 'textfield', '#title' => t('Link path'), '#default_value' => $bean->more_link['path']);
     return $form;
 }
 public function exists(NodeInterface $node, Context $context)
 {
     /* @var $node ViewNode */
     $entityType = $node->getEntityType();
     $name = $node->getName();
     $info = entity_get_info($entityType);
     return isset($info) && ('default' === $name || isset($info['view modes'][$name]));
 }
 /**
  * @test
  */
 public function it_can_access_the_database()
 {
     if (!function_exists('entity_get_info')) {
         $this->fail('Drupal not bootstrapped.');
     }
     $entityInfo = entity_get_info();
     $this->assertCount(6, $entityInfo, 'Entity info returned.');
 }
Example #10
0
 /**
  * Constructor.
  *
  * This is private since we want consumers to instantiate via the factory methods.
  *
  * @param object $node
  *   A Drupal node.
  */
 private function __construct($entity, $entity_type)
 {
     $this->entity = $entity;
     $this->language = $entity->language;
     $this->language_targets = Lingotek::getLanguagesWithoutSource($this->language);
     $this->entity_type = $entity_type;
     $this->info = entity_get_info($this->entity_type);
 }
Example #11
0
 public function handlesEntity(Entity $entity)
 {
     if (!module_exists('xmlsitemap')) {
         return false;
     }
     $info = entity_get_info($entity->type());
     return array_key_exists('xmlsitemap', $info) && is_array($info['xmlsitemap']);
 }
 /**
  * Get list of entity info arrays, keyed by the entity's token-like name.
  *
  * @return array
  *    List of entity info arrays.
  */
 protected function getEntityTokenTypes()
 {
     $return = array();
     foreach (entity_get_info() as $entity_type => $entity_info) {
         $entity_type = $entity_type == 'taxonomy_term' ? 'term' : $entity_type;
         $return[$entity_type] = $entity_info;
     }
     return $return;
 }
 public function __construct($name, $info)
 {
     $this->apiMap = restws_schema_map_get();
     $this->propertyInfo = $info['properties'];
     $this->resource = $name;
     $this->entityType = $this->apiMap[$name]['entity'];
     $this->bundleName = $this->apiMap[$name]['bundle'];
     $this->entityInfo = entity_get_info($this->apiMap[$name]['entity']);
 }
Example #14
0
 /**
  * {@inheritdoc}
  *
  * @todo Do we want to limit to content entities? There's a lot in the list.
  */
 public function getDerivativeDefinitions(array $base_plugin_definition)
 {
     foreach (entity_get_info() as $entity_type => $entity_info) {
         $this->derivatives[$entity_type] = $base_plugin_definition;
         $this->derivatives[$entity_type]['title'] = $entity_info['label'];
         $this->derivatives[$entity_type]['entity type'] = $entity_type;
     }
     $this->sortDerivatives();
     return $this->derivatives;
 }
 /**
  * {@inheritdoc}
  */
 public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL)
 {
     $target_entity_type = $field['settings']['target_type'];
     // Check if the entity type does exist and has a base table.
     $entity_info = entity_get_info($target_entity_type);
     if (empty($entity_info['base table']) || $target_entity_type != 'user') {
         return EntityReference_SelectionHandler_Broken::getInstance($field, $instance);
     }
     return new ProjectIssue_SelectionHandler_Assigned($field, $instance, $entity_type, $entity);
 }
 /**
  * Returns available entity types.
  *
  * @return array
  *   A list of entity types keyed by machine name => label.
  */
 public function getEntityTypeOptions()
 {
     $entity_type_options =& drupal_static(__METHOD__);
     if (empty($entity_type_options)) {
         $info = entity_get_info();
         foreach ($info as $entity_type => $entity_type_info) {
             $entity_type_options[$entity_type] = $entity_type_info['label'];
         }
     }
     return $entity_type_options;
 }
Example #17
0
 /**
  * Constructor.
  *
  * This is private since we want consumers to instantiate via the factory methods.
  *
  * @param object $node
  *   A Drupal node.
  */
 private function __construct($entity, $entity_type)
 {
     $this->entity = $entity;
     $this->entity_type = $entity_type;
     $this->info = entity_get_info($this->entity_type);
     if (!empty($entity->language_override)) {
         $this->setLanguage($entity->language_override);
     } else {
         $this->setLanguage();
     }
 }
 /**
  * {@inheritdoc}
  */
 public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL)
 {
     $target_entity_type = $field['settings']['target_type'];
     // Check if the entity type does exist and has a base table.
     $entity_info = entity_get_info($target_entity_type);
     // We only work with a target of 'node', as issues must be nodes.
     if (empty($entity_info['base table']) || $target_entity_type != 'node') {
         return EntityReference_SelectionHandler_Broken::getInstance($field, $instance);
     }
     return new ProjectIssue_SelectionHandler_Issues($field, $instance, $entity_type, $entity);
 }
 public function views_data_alter(&$data, $field)
 {
     $entity_info = entity_get_info($field['settings']['target_type']);
     $field_name = $field['field_name'] . '_target_id';
     foreach ($data as $table_name => &$table_data) {
         if (isset($table_data[$field_name])) {
             // Set the entity id filter to use the in_operator handler with our
             // own callback to return the values.
             $table_data[$field_name]['filter']['handler'] = 'views_handler_filter_entityreference_autocomplete';
         }
     }
 }
 public function getExtractDependencies(NodeInterface $node, Context $context)
 {
     $ret = $this->getDependencies($node, $context);
     $bundle = $node->getBundle();
     // Let's go for view modes too
     $view = [];
     $view[] = 'view.node.' . $bundle . '.default';
     foreach (entity_get_info('node')['view modes'] as $viewMode => $settings) {
         $view[] = 'view.node.' . $bundle . '.' . $viewMode;
     }
     return array_merge($ret, $view);
 }
Example #21
0
 /**
  * Helper method for describe()
  *
  * @param crumbs_InjectedAPI_describeMultiPlugin $api
  * @param string $entity_type
  * @param string $label
  * @return array
  */
 protected function describeGeneric($api, $entity_type, $label)
 {
     $info = entity_get_info($entity_type);
     $keys = array();
     foreach ($info['bundles'] as $bundle_key => $bundle) {
         $keys[$bundle_key] = t('!key: !value', array('!key' => $label, '!value' => $bundle['label']));
     }
     if (method_exists($this->plugin, 'describe')) {
         $keys = $this->plugin->describe($api, $entity_type, $keys);
         return $keys;
     } else {
         return $keys;
     }
 }
 /**
  * Get entity controller
  *
  * @param string $entityType
  *
  * @return EntityStorageInterface
  */
 public function getStorage($entityType)
 {
     switch ($entityType) {
         case 'node':
             return new NodeStorage($entityType);
         case 'user':
             return new UserStorage($entityType);
         default:
             if (!entity_get_info($entityType)) {
                 throw new \InvalidArgumentException(sprintf('%s: entity type does not exist', $entityType));
             }
             return new DefaultEntityStorageProxy($entityType);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * Implements FeedsEntityProcessorPropertyInterface::validate().
  */
 public function validate(&$value)
 {
     $info = $this->getPropertInfo();
     $entity_type = $info['type'];
     if ($value) {
         $entity = entity_load_single($entity_type, $value);
         if (!$entity) {
             $entity_info = entity_get_info();
             $entity_type_label = $entity_info[$entity_type]['label'];
             return array(t('@entity_type with id @entity_id does not exist.', array('@entity_type' => $entity_type_label, '@entity_id' => $value)));
         }
         $wrapper = entity_metadata_wrapper($entity_type, $value);
         return parent::validate($wrapper);
     }
 }
 /**
  * Overrides EntityReference_SelectionHandler_Generic_taxonomy_term::entityFieldQueryAlter().
  * Adds language filtering logic.
  */
 public function entityFieldQueryAlter(SelectQueryInterface $query)
 {
     parent::entityFieldQueryAlter($query);
     $base_table = $this->ensureBaseTable($query);
     $entity_info = entity_get_info($this->field['settings']['target_type']);
     if ($this->field['settings']['handler_settings']['filter']['language'] == 1 && $entity_info['translation']['locale'] == TRUE) {
         $term_language = i18n_taxonomy_i18n_context_language();
         if (isset($term_language->language) && !is_null($term_language->language)) {
             $query->condition("{$base_table}.language", $term_language->language);
         }
     } else {
         global $language;
         $query->condition("{$base_table}.language", $language->language);
     }
 }
 /**
  * Build an EntityFieldQuery to get referencable entities.
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // The "node_access" tag causes errors, so we replace it with
     // "entity_field_access" tag instead.
     // @see _node_query_node_access_alter().
     unset($query->tags['node_access']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     $group_type = $this->field['settings']['target_type'];
     $entity_info = entity_get_info($group_type);
     if (!field_info_field(OG_GROUP_FIELD)) {
         // There are no groups, so falsify query.
         $query->propertyCondition($entity_info['entity keys']['id'], -1, '=');
         return $query;
     }
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1, '=');
     $user_groups = og_get_groups_by_user(NULL, $group_type);
     $reference_type = $this->field['settings']['handler_settings']['reference_type'];
     // Show the user only the groups they belong to.
     if ($reference_type == 'my_groups') {
         if ($user_groups && !empty($this->instance) && $this->instance['entity_type'] == 'node') {
             // Check if user has "create" permissions on those groups.
             $node_type = $this->instance['bundle'];
             $ids = array();
             foreach ($user_groups as $gid) {
                 if (og_user_access($group_type, $gid, "create {$node_type} content")) {
                     $ids[] = $gid;
                 }
             }
         } else {
             $ids = $user_groups;
         }
         if ($ids) {
             $query->propertyCondition($entity_info['entity keys']['id'], $ids, 'IN');
         } else {
             // User doesn't have permission to select any group so falsify this
             // query.
             $query->propertyCondition($entity_info['entity keys']['id'], -1, '=');
         }
     } elseif ($reference_type == 'other_groups' && $user_groups) {
         // Show only group the user doesn't belong to.
         $query->propertyCondition($entity_info['entity keys']['id'], $user_groups, 'NOT IN');
     }
     return $query;
 }
 /**
  * Initialize this plugin with the plugin, profile, and entity specific
  * variables.
  *
  * @param object $profile
  *   The Linkit profile to use.
  * @param array $plugin
  *   The plugin array.
  */
 function __construct($plugin, $profile)
 {
     parent::__construct($plugin, $profile);
     // Load the corresponding entity.
     $this->entity_info = entity_get_info($this->plugin['entity_type']);
     // Set bundle key name.
     if (isset($this->entity_info['entity keys']['bundle']) && !isset($this->entity_key_bundle)) {
         $this->entity_key_bundle = $this->entity_info['entity keys']['bundle'];
     }
     // Set the label field name.
     if (!isset($this->entity_field_label)) {
         $this->entity_field_label = $this->entity_info['entity keys']['label'];
     }
     // Make a shortcut for the profile data settings for this plugin.
     $this->conf = isset($this->profile->data[$this->plugin['name']]) ? $this->profile->data[$this->plugin['name']] : array();
 }
 /**
  * Returns an entity wrapper class for the entity type provided.
  *
  * @param mixed $data
  *   The data to pass to the wrapper class constructor. Usually the id or
  *   loaded entity.
  * @param string $entity_type
  *   The entity type to load the class for.
  * @param string $bundle
  *   (optional) The bundle of the entity type to retrieve the class for.
  *
  * @return EntityWrapper
  */
 public static function getWrapper($data, $entity_type, $bundle = self::NO_BUNDLE)
 {
     $info = entity_get_info($entity_type);
     if ($bundle !== static::NO_BUNDLE) {
         if (isset($info['bundles'][$bundle]['entity_wrappers']['class'])) {
             $class = $info['bundles'][$bundle]['entity_wrappers']['class'];
         } else {
             throw new InvalidArgumentException(static::invalidBundleMessage($bundle));
         }
     } elseif (isset($info['entity_wrappers']['class'])) {
         $class = $info['entity_wrappers']['class'];
     } else {
         throw new InvalidArgumentException(static::invalidEntityTypeMessage($entity_type));
     }
     return new $class($data);
 }
Example #29
0
 public function __construct(Entity $entity, $old_revision_id = null, $new_revision_id = null)
 {
     $this->entity = $entity;
     $entity_info = \entity_get_info($entity->type());
     if (array_key_exists('revision table', $entity_info)) {
         $this->revisions_table = $entity_info['revision table'];
     }
     if (array_key_exists('entity keys', $entity_info)) {
         $this->entity_keys = $entity_info['entity keys'];
     }
     // If we have a menu link, don't send every single revision. Because we don't need them.
     if ($this->entity->type() == 'menu_link') {
         $this->revisions_table = false;
     }
     $this->old_revision_id = $old_revision_id;
     $this->new_revision_id = $new_revision_id;
 }
 /**
  * {@inheritdoc}
  */
 public function expand($values)
 {
     $entity_type = $this->fieldInfo['settings']['target_type'];
     $entity_info = entity_get_info($entity_type);
     // For users set label to username.
     if ($entity_type == 'user') {
         $entity_info['entity keys']['label'] = 'name';
     }
     $return = array();
     foreach ($values as $value) {
         $target_id = db_select($entity_info['base table'], 't')->fields('t', array($entity_info['entity keys']['id']))->condition('t.' . $entity_info['entity keys']['label'], $value)->execute()->fetchField();
         if ($target_id) {
             $return[$this->language][] = array('target_id' => $target_id);
         }
     }
     return $return;
 }