/** * Get the DB column name from a property. * * The "property" defined in the public field is actually the property * of the entity metadata wrapper. Sometimes that property can be a * different name than the column in the DB. For example, for nodes the * "uid" property is mapped in entity metadata wrapper as "author", so * we make sure to get the real column name. * * @param string $property_name * The property name. * * @return string * The column name. */ protected function getColumnFromProperty($property_name) { $property_info = entity_get_property_info($this->entityType); return $property_info['properties'][$property_name]['schema field']; }
/** * Define new types of items that can be searched. * * This hook allows modules to define their own item types, for which indexes * can then be created. (Note that the Search API natively provides support for * all entity types that specify property information, so they should not be * added here. You should therefore also not use an existing entity type as the * identifier of a new item type.) * * The main part of defining a new item type is implementing its data source * controller class, which is responsible for loading items, providing metadata * and tracking existing items. The module defining a certain item type is also * responsible for observing creations, updates and deletions of items of that * type and notifying the Search API of them by calling * search_api_track_item_insert(), search_api_track_item_change() and * search_api_track_item_delete(), as appropriate. * The only other restriction for item types is that they have to have a single * item ID field, with a scalar value. This is, e.g., used to track indexed * items. * * Note, however, that you can also define item types where some of these * conditions are not met, as long as you are aware that some functionality of * the Search API and related modules might then not be available for that type. * * @return array * An associative array keyed by item type identifier, and containing type * information arrays with at least the following keys: * - name: A human-readable name for the type. * - datasource controller: A class implementing the * SearchApiDataSourceControllerInterface interface which will be used as * the data source controller for this type. * - entity_type: (optional) If the type represents entities, the entity type. * This is used by SearchApiAbstractDataSourceController for determining the * entity type of items. Other datasource controllers might ignore this. * Other, datasource-specific settings might also be placed here. These should * be specified with the data source controller in question. * * @see hook_search_api_item_type_info_alter() */ function hook_search_api_item_type_info() { // Copied from search_api_search_api_item_type_info(). $types = array(); foreach (entity_get_property_info() as $type => $property_info) { if ($info = entity_get_info($type)) { $types[$type] = array('name' => $info['label'], 'datasource controller' => 'SearchApiEntityDataSourceController', 'entity_type' => $type); } } return $types; }
/** * Is the field name a property? * @param string $field_name * @return boolean */ protected function isProperty($field_name) { $property_info = entity_get_property_info($this->entityType); return in_array($field_name, array_keys($property_info['properties'])); }
/** * Implements EntityExtraFieldsControllerInterface::fieldExtraFields(). */ public function fieldExtraFields() { $extra = array(); $this->propertyInfo = entity_get_property_info($this->entityType); if (isset($this->propertyInfo['properties'])) { foreach ($this->propertyInfo['properties'] as $name => $property_info) { // Skip adding the ID or bundle. if ($this->entityInfo['entity keys']['id'] == $name || $this->entityInfo['entity keys']['bundle'] == $name) { continue; } $extra[$this->entityType][$this->entityType]['display'][$name] = $this->generateExtraFieldInfo($name, $property_info); } } // Handle bundle properties. $this->propertyInfo += array('bundles' => array()); if (isset($this->propertyInfo['bundles'])) { foreach ($this->propertyInfo['bundles'] as $bundle_name => $info) { foreach ($info['properties'] as $name => $property_info) { if (empty($property_info['field'])) { $extra[$this->entityType][$bundle_name]['display'][$name] = $this->generateExtraFieldInfo($name, $property_info); } } } } return $extra; }
/** * As seen in commerce_services... * * Returns a list of fields for the specified entity type. * * @param string $entity_type * Machine-name of the entity type whose properties should be returned. * @param string $bundle * Optional bundle name to limit the returned fields to. * * @return array * An associative array of fields for the specified entity type with the key * being the field name and the value being the Entity API property type. */ public static function entityTypeFields($entity_type, $bundle = NULL) { $fields = drupal_static(__FUNCTION__); if (!isset($fields[$entity_type])) { $info = entity_get_property_info($entity_type); $fields = array(); // Loop over the bundles info to inspect their fields. foreach ($info['bundles'] as $bundle_name => $bundle_info) { // Loop over the properties on the bundle to find field information. foreach ($bundle_info['properties'] as $key => $value) { if (!empty($value['field'])) { $fields[$entity_type][$bundle_name][$key] = $value['type']; } } } } // If a specific bundle's fields was requested, return just those. if (!empty($bundle)) { return $fields[$entity_type][$bundle]; } else { // Otherwise combine all the fields for various bundles of the entity type // into a single return value. $combined_fields = array(); foreach ($fields[$entity_type] as $bundle_name => $bundle_fields) { $combined_fields += $bundle_fields; } return $combined_fields; } }