/** * Additional columns and views need to be added to existing fields. * Below is an example using the addtional column and view defined above. * my_new_view_additional_data() is schema defined in * hook_recline_field_columns. */ function hook_update_N(&$sandbox) { $ret = array(); $fields = field_info_fields(); foreach ($fields as $field_name => $field) { if ($field['type'] == 'recline_field' && $field['storage']['type'] == 'field_sql_storage') { foreach ($field['storage']['details']['sql'] as $type => $table_info) { foreach ($table_info as $table_name => $columns) { $column_name = _field_sql_storage_columnname($field_name, 'my_new_view_additional_data'); // Adding my_new_view_additional_data. if (!db_field_exists($table_name, $column_name)) { // Calling schema defined in hook_recline_field_column(). $schema = my_new_view_additional_data(); db_add_field($table_name, $column_name, $schema); } // Adding my_new_view. $column_name = _field_sql_storage_columnname($field_name, 'my_new_view'); $schema = recline_field_schema(); if (!db_field_exists($table_name, $column_name)) { db_add_field($table_name, $column_name, $schema['columns']['my_new_view']); } field_cache_clear(); } } } } return $ret; }
/** * {@inheritdoc} */ public static function settingsForm($field, $instance) { $referenced_fields = array(); foreach (field_info_fields() as $f) { if (isset($f['bundles'][$instance['entity_type']]) && in_array($instance['bundle'], $f['bundles'][$instance['entity_type']]) && $f['type'] == 'entityreference') { $referenced_fields[$f['field_name']] = $f['field_name']; } } $form['project_field'] = array('#type' => 'select', '#title' => t('Field containing project reference'), '#options' => $referenced_fields, '#default_value' => isset($field['settings']['handler_settings']['project_field']) ? $field['settings']['handler_settings']['project_field'] : 'none'); $form += parent::settingsForm($field, $instance); return $form; }
/** * Override settings form(). */ public static function settingsForm($field, $instance) { $form = parent::settingsForm($field, $instance); $entity_type = $field['settings']['target_type']; $entity_info = entity_get_info($entity_type); $bundles = array(); foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) { if (og_is_group_type($entity_type, $bundle_name)) { $bundles[$bundle_name] = $bundle_info['label']; } } if (!$bundles) { $form['target_bundles'] = array('#type' => 'item', '#title' => t('Target bundles'), '#markup' => t('Error: The selected "Target type" %entity does not have bundles that are a group type', array('%entity' => $entity_info['label']))); } else { $settings = $field['settings']['handler_settings']; $settings += array('target_bundles' => array(), 'membership_type' => OG_MEMBERSHIP_TYPE_DEFAULT, 'reference_type' => 'my_groups', 'primary_field' => FALSE, 'hide_secondary_field' => TRUE); $form['target_bundles'] = array('#type' => 'select', '#title' => t('Target bundles'), '#options' => $bundles, '#default_value' => $settings['target_bundles'], '#size' => 6, '#multiple' => TRUE, '#description' => t('The bundles of the entity type acting as group, that can be referenced. Optional, leave empty for all bundles.')); $options = array(); foreach (og_membership_type_load() as $og_membership) { $options[$og_membership->name] = $og_membership->description; } $form['membership_type'] = array('#type' => 'select', '#title' => t('OG membership type'), '#description' => t('Select the membership type that will be used for a subscribing user.'), '#options' => $options, '#default_value' => $settings['membership_type'], '#required' => TRUE); $form['reference_type'] = array('#type' => 'select', '#title' => t('Reference'), '#options' => array('my_groups' => t('My groups'), 'other_groups' => t('Other groups'), 'all_groups' => t('All groups')), '#description' => t('What groups should be referenced.'), '#default_value' => $settings['reference_type']); $options = array('0' => t('None')); // Get all the other group audience fields in this bundle. $entity_type = $instance['entity_type']; $bundle = $instance['bundle']; $fields_info = field_info_fields(); foreach (field_info_instances($entity_type, $bundle) as $field_name => $field_instance) { if ($field_name == $field['field_name']) { // This is the current field. continue; } if ($fields_info[$field_name]['type'] != 'entityreference' || $fields_info[$field_name]['settings']['handler'] != 'og') { // This is not an Entity reference field. continue; } if (!empty($fields_info[$field_name]['settings']['handler_settings']['primary_field'])) { // Field is already a secondary field. continue; } $options[$field_name] = $field_instance['label'] . ' (' . $field_name . ')'; } $form['primary_field'] = array('#type' => 'select', '#title' => t('Primary field'), '#description' => t('Select a field that will be populated with the values of this field.'), '#options' => $options, '#default_value' => $settings['primary_field'], '#required' => TRUE, '#element_validate' => array('og_handler_primary_field_validate')); $form['hide_secondary_field'] = array('#type' => 'checkbox', '#title' => t('Hide secondary field'), '#description' => t('Show the secondary field only to users with "administer group" permission.'), '#default_value' => $settings['hide_secondary_field'], '#states' => array('invisible' => array(':input[name="field[settings][handler_settings][primary_field]"]' => array('value' => 0)))); form_load_include($form_state, 'php', 'og', '/plugins/selection/og.class'); } return $form; }
function dxray_get_fields_info() { $REID = array('nodes' => array(), 'edges' => array()); // будем вести учет ID в GML и его названия $GML = new GraphML(); $fields = field_info_fields(); $aMethods = array(); foreach ($fields as $field) { $data['attributes'] = array('Name: ' . $field['field_name'], 'Type: ' . $field['type'], 'Module: ' . $field['module']); //$field['bundles'] ['node'][0] = 'faq'; $ID = $GML->addNode($field['field_name'], 'UMLClassNode', null, $data); _dxray_parse_bundles($ID, $field['bundles'], $REID, $GML); $REID['nodes'][$field['field_name']] = $ID; } $file = DXRAY_OUTPATH . '/FieldS-' . date('d-m-Y_H-i-s') . '.graphml'; $GML->createFullGraphML($file); }
function test_preprocess_node(&$vars) { // Custom display templates will be called node--[viewmode].tpl.php $vars['theme_hook_suggestions'][] = 'node__' . $vars['view_mode']; // Custom display templates will be called node--[type]--[viewmode].tpl.php $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode']; // Custom display templates will be called node--[type]--[viewmode]--[nid].tpl.php $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'] . '__' . $vars['node']->nid; $fields = field_info_fields(); foreach ($fields as $name => $field) { if (!isset($vars['content'][$name])) { $vars['content'][$name] = array(); } } $node = $vars['node']; $type = $vars['type']; $viewmode = $vars['view_mode']; }
/** * hook_preprocess_field__field_resources() * Prepare resource data from field collection to create file/language table for resources * @todo add a method to count how many languages are available in language field (currently 4) and pass to template */ function gitp_preprocess_field__field_documents(&$variables) { $items = $variables['items']; $documents = array(); $fields = field_info_fields(); $languages = list_allowed_values($fields['field_fc_resource_language']); $lang_count = count($languages); $processed = array(); foreach ($languages as $language => $lang_value) { foreach ($items as $key => $item) { foreach ($item['entity']['field_collection_item'] as $delta => $fc_item) { $delta_lang = $fc_item['field_fc_resource_language'][0]['#markup']; $title = $fc_item['field_fc_resource_file_title'][0]['#markup']; if ($lang_value == $delta_lang) { $url = ''; if (isset($fc_item['field_fc_document_file'])) { $url = file_create_url($fc_item['field_fc_document_file']['#items'][0]['uri']); } if (!array_key_exists($title, $documents)) { $documents[$title] = array(); } if (!array_key_exists($lang_value, $documents[$title])) { $documents[$title][$lang_value] = array(); } $documents[$title][$lang_value] = $url; } else { if (!isset($documents[$title][$lang_value])) { $documents[$title][$lang_value] = NULL; } } } } $processed[$lang_value] = TRUE; } $variables['element']['resources_table_data'] = $documents; $variables['element']['available_language_count'] = $lang_count; }
/** * Load field data for a set of entities. * * This hook is invoked from field_attach_load() to ask the field storage * module to load field data. * * Modules implementing this hook should load field values and add them to * objects in $entities. Fields with no values should be added as empty * arrays. * * @param $entity_type * The type of entity, such as 'node' or 'user'. * @param $entities * The array of entity objects to add fields to, keyed by entity ID. * @param $age * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or * FIELD_LOAD_REVISION to load the version indicated by each entity. * @param $fields * An array listing the fields to be loaded. The keys of the array are field * names, and the values of the array are the entity IDs (or revision IDs, * depending on the $age parameter) to add each field to. Note that deleted * data may need to be loaded, so requests to field_info_fields() should * the $include_deleted flag to ensure the field definition is loaded. * @param $options * An associative array of additional options, with the following keys: * - deleted: If TRUE, deleted fields should be loaded as well as * non-deleted fields. If unset or FALSE, only non-deleted fields should be * loaded. */ function hook_field_storage_load($entity_type, $entities, $age, $fields, $options) { $field_info = field_info_fields(TRUE); $load_current = $age == FIELD_LOAD_CURRENT; foreach ($fields as $field_name => $entity_ids) { $field = $field_info[$field_name]; $field_name = $field['field_name']; $table = $load_current ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field); $query = db_select($table, 't')->fields('t')->condition('entity_type', $entity_type)->condition($load_current ? 'entity_id' : 'revision_id', $entity_ids, 'IN')->condition('language', field_available_languages($entity_type, $field), 'IN')->orderBy('delta'); if (empty($options['deleted'])) { $query->condition('deleted', 0); } $results = $query->execute(); $delta_count = array(); foreach ($results as $row) { if (!isset($delta_count[$row->entity_id][$row->language])) { $delta_count[$row->entity_id][$row->language] = 0; } if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->language] < $field['cardinality']) { $item = array(); // For each column declared by the field, populate the item // from the prefixed database column. foreach ($field['columns'] as $column => $attributes) { $column_name = _field_sql_storage_columnname($field_name, $column); $item[$column] = $row->{$column_name}; } // Add the item to the field values for the entity. $entities[$row->entity_id]->{$field_name}[$row->language][] = $item; $delta_count[$row->entity_id][$row->language]++; } } } }
public static function getFields($type = null) { return $type ? field_info_field($type) : field_info_fields(); }
/** * Find all field columns that have data that refer to entities. * * @return array */ public static function getEntityReferencingFields() { $results = array(); if ($cache = cache_get('field_info:helper_referencing_fields', 'cache_field')) { $results = $cache->data; } else { $entity_info = entity_get_info(); $base_tables = array(); foreach ($entity_info as $type => $type_info) { if (!empty($type_info['base table']) && !empty($type_info['entity keys']['id'])) { $base_tables[$type_info['base table']] = array('type' => $type, 'column' => $type_info['entity keys']['id']); } } $fields = field_info_fields(); foreach ($fields as $field) { // Cannot rely on entityreference fields having correct foreign key info. // @todo Remove when http://drupal.org/node/1969018 is fixed. if ($field['type'] == 'entityreference') { $results[$field['field_name']]['target_id'] = $field['settings']['target_type']; continue; } foreach ($field['foreign keys'] as $foreign_key) { if (isset($base_tables[$foreign_key['table']])) { $base_table = $base_tables[$foreign_key['table']]; if ($column = array_search($base_table['column'], $foreign_key['columns'])) { $results[$field['field_name']][$column] = $base_table['type']; } } } } drupal_alter('helper_field_get_referencing_fields', $results, $fields); cache_set('field_info:helper_referencing_fields', $results, 'cache_field'); } return $results; }
/** * Implements Drupal\configuration\Config\Configuration::saveToActiveStore(). */ public function saveToActiveStore(ConfigIteratorSettings &$settings) { field_info_cache_clear(); // Load all the existing fields and instance up-front so that we don't // have to rebuild the cache all the time. $existing_fields = field_info_fields(); $existing_instances = field_info_instances(); $field = $this->getData(); // Create or update field. $field_config = $field['field_config']; if (isset($existing_fields[$field_config['field_name']])) { $existing_field = $existing_fields[$field_config['field_name']]; if ($field_config + $existing_field != $existing_field) { field_update_field($field_config); } } else { field_create_field($field_config); $existing_fields[$field_config['field_name']] = $field_config; } // Create or update field instance. $field_instance = $field['field_instance']; if (isset($existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']])) { $existing_instance = $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']]; if ($field_instance + $existing_instance != $existing_instance) { field_update_instance($field_instance); } } else { field_create_instance($field_instance); $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']] = $field_instance; } variable_set('menu_rebuild_needed', TRUE); $settings->addInfo('imported', $this->getUniqueId()); }
<?php $all_fields_on_my_website = field_info_fields(); ?> <div class="contact"> <table class="common-module common-table contacts__table"> <tr class="common-table__row"> <?php if (isset($node->field_programm_type['und'][0]['taxonomy_term']->name)) { ?> <td class="common-table__cell"> <span class="common-table__cell--header">Тип программы</span> <?php print $node->field_programm_type['und'][0]['taxonomy_term']->name; ?> </td> <?php } ?> <?php if (isset($node->field_programm_base['und'])) { ?> <td class="common-table__cell"> <span class="common-table__cell--header">Основа обучения</span> <?php $bases = list_allowed_values($all_fields_on_my_website["field_programm_base"]); $vals = array(); ?> <?php foreach ($node->field_programm_base['und'] as $k => $v) {
/** * Drupal 6 */ protected function readDrupal7SiteProperties() { $entityInfo = entity_get_info(); $this->entityTypes = array(); foreach ($entityInfo as $entity_type => $entity_info) { if (in_array($entity_type, array('node', 'taxonomy_term'))) { foreach ($entity_info['bundles'] as $bundle => $bundleInfo) { if ($instanceInfo = field_info_instances($entity_type, $bundle)) { foreach ($instanceInfo as $instance) { $this->instances[] = $this->processInstance($instance); } } switch ($entity_type) { case 'node': $node_type = node_type_load($bundle); $this->entityTypes[] = new NodeTypeBuilder($bundle, $bundleInfo['label'], $node_type->description); break; case 'taxonomy_term': $vocabulary = taxonomy_vocabulary_machine_name_load($bundle); $this->entityTypes[] = new VocabularyBuilder($bundle, $bundleInfo['label'], $vocabulary->description); break; } } } } $fieldInfo = field_info_fields(); foreach ($fieldInfo as $fieldName => $info) { $this->fields[$fieldName] = new FieldBuilder($fieldName, $info['type']); } $this->parseDefinition(); }