/**
 * Implements hook_form_system_theme_settings_alter().
 */
function bootstrap_clean_blog_form_system_theme_settings_alter(&$form, $form_state, $form_id = NULL)
{
    // Work-around for a core bug affecting admin themes. See issue #943212.
    if (isset($form_id)) {
        return;
    }
    $form['instant_vertical_tabs'] = array('#type' => 'vertical_tabs', '#prefix' => '<h2><small>' . t('Bootstrap Clean Blog settings') . '</small></h2>');
    $form['header'] = array('#type' => 'fieldset', '#title' => t('Site header'), '#group' => 'instant_vertical_tabs');
    $article_fields = (array) field_info_instances('node', 'article');
    if (!empty($article_fields)) {
        foreach ($article_fields as $key => $field) {
            if ($field['widget']['type'] !== 'image_image') {
                unset($article_fields[$key]);
            } else {
                $article_fields[$key] = $field['field_name'];
            }
        }
    }
    $fields = (array) array_merge(array('none' => t('-- Select --')), $article_fields);
    $form['header']['header_image'] = array('#type' => 'select', '#title' => t('Header image'), '#options' => $fields, '#description' => t('Big image for nodes, display in header. The field must be created for all types of material.'), '#default_value' => theme_get_setting('header_image'));
    $form['social_buttons'] = array('#type' => 'fieldset', '#title' => t('Social buttons'), '#group' => 'instant_vertical_tabs');
    $form['social_buttons']['social_facebook'] = array('#type' => 'textfield', '#title' => t('Facebook'), '#default_value' => theme_get_setting('social_facebook'));
    $form['social_buttons']['social_twitter'] = array('#type' => 'textfield', '#title' => t('Twitter'), '#default_value' => theme_get_setting('social_twitter'));
    $form['social_buttons']['social_github'] = array('#type' => 'textfield', '#title' => t('Github'), '#default_value' => theme_get_setting('social_github'));
}
示例#2
0
 /**
  * Overrides Drupal\configuration\Config\Configuration::alterDependencies().
  */
 public static function alterDependencies(Configuration $config)
 {
     if ($config->getComponent() == 'content_type') {
         $variables = array('field_bundle_settings_node_', 'language_content_type', 'node_options', 'node_preview', 'node_submitted');
         if (module_exists('comment')) {
             $variables += array('comment', 'comment_anonymous', 'comment_controls', 'comment_default_mode', 'comment_default_order', 'comment_default_per_page', 'comment_form_location', 'comment_preview', 'comment_subject_field');
         }
         if (module_exists('menu')) {
             $variables += array('menu_options', 'menu_parent');
         }
         $entity_type = $config->getEntityType();
         $fields = field_info_instances($entity_type, $config->getIdentifier());
         foreach ($variables as $variable) {
             $identifier = $variable . '_' . $config->getIdentifier();
             $in_db = db_query("SELECT 1 FROM {variable} WHERE name = :name", array(':name' => $identifier))->fetchField();
             // Some variables are not in the database and their values are
             // provided by the second paramenter of variable_get.
             // Only inform about configurations that are indeed in the database.
             if ($in_db) {
                 $var_config = new VariableConfiguration($identifier);
                 $var_config->build();
                 $config->addToDependencies($var_config);
             }
         }
     }
 }
示例#3
0
/**
 *  Получаем список NODE_TYPE
 * modules/node/node.module
 * @link https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_info/7 description param
 * @link https://www.drupal.org/node/1027630 info
 */
function dxray_get_node_type()
{
    $GML = new GraphML();
    $optN1 = $GML->setOptionsNode()->Fill_setColor('#ccffff')->Label_setFontSize('22')->getOptions();
    $aNtypes = node_type_get_types();
    foreach ($aNtypes as $oType) {
        // 1. Сначала создаем узел NODE_TYPE
        $data['attributes'] = array('Base: ' . $oType->base, 'Type: ' . $oType->type, 'Help: ' . PHP_EOL . $oType->help . PHP_EOL, 'Custom: ' . $oType->custom, 'Modified: ' . $oType->modified, 'Locked: ' . $oType->locked, 'Disabled: ' . $oType->disabled, 'Is new: ' . $oType->is_new, 'Has title: ' . $oType->has_title, 'Title label: ' . $oType->title_label, 'Module: ' . $oType->module);
        $options['NodeFill']['color'] = '#ccffff';
        $ID_bundle = $GML->addNode($oType->name, 'UMLClassNode', $optN1, $data);
        dxray_debug_stdout('Добавили bundle номер: ' . $ID_bundle);
        // 2. Получаем поля данного контента и строем зависимости
        $fields = field_info_instances('node', $oType->type);
        foreach ($fields as $field) {
            $finfo = field_info_field($field['field_name']);
            $data['attributes'] = array('Label: ' . $field['label'], 'Required: ' . $field['required'], 'Module: ' . $finfo['module'], 'Locked: ' . $finfo['locked'], 'Cardinality: ' . $finfo['cardinality'], 'Description: ' . $field['description']);
            $dataHTML['attributes'] = array('<html>', 'Label: ' . $field['label'] . '<br>', 'Required: ' . $field['required'] . '<br>', '<b>Module:</b> ' . $finfo['module'] . '<br>', 'Locked: ' . $finfo['locked'] . '<br>', 'Cardinality: ' . $finfo['cardinality'] . '<br>', 'Description: ' . $field['description'] . '<br>', '</html>');
            $ID_field = $GML->addNode($field['field_name'], 'UMLClassNode', null, $dataHTML);
            dxray_debug_stdout('Добавили field номер: ' . $ID_field);
            dxray_debug_stdout("{EDGE} SRC: {$ID_bundle} TARGET: {$ID_field} " . $ID_field);
            $GML->addEdge($ID_bundle, $ID_field);
        }
    }
    $file = DXRAY_OUTPATH . '/NodeType-' . date('d-m-Y_H-i-s') . '.graphml';
    $GML->createFullGraphML($file);
    $dbg = 0;
}
 /**
  * Implements EntityReferenceHandler::settingsForm().
  */
 public static function settingsForm($field, $instance)
 {
     $entity_info = entity_get_info($field['settings']['target_type']);
     if (!empty($entity_info['entity keys']['bundle'])) {
         $bundles = array();
         foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
             $bundles[$bundle_name] = $bundle_info['label'];
         }
         $form['target_bundles'] = array('#type' => 'select', '#title' => t('Target bundles'), '#options' => $bundles, '#default_value' => isset($field['settings']['handler_settings']['target_bundles']) ? $field['settings']['handler_settings']['target_bundles'] : array(), '#size' => 6, '#multiple' => TRUE, '#description' => t('The bundles of the entity type that can be referenced. Optional, leave empty for all bundles.'));
     } else {
         $form['target_bundles'] = array('#type' => 'value', '#value' => array());
     }
     $form['sort']['type'] = array('#type' => 'radios', '#title' => t('Sort by'), '#options' => array('none' => t("Don't sort"), 'property' => t('A property of the base table of the entity'), 'field' => t('A field attached to this entity')), '#default_value' => isset($field['settings']['handler_settings']['sort']['type']) ? $field['settings']['handler_settings']['sort']['type'] : 'none');
     $form['sort']['property'] = array('#type' => 'select', '#title' => t('Sort property'), '#options' => drupal_map_assoc($entity_info['schema_fields_sql']['base table']), '#default_value' => isset($field['settings']['handler_settings']['sort']['property']) ? $field['settings']['handler_settings']['sort']['property'] : '', '#states' => array('visible' => array(':input[name="field[settings][handler_settings][sort][type]"]' => array('value' => 'property'))));
     $fields = array();
     foreach (field_info_instances($field['settings']['target_type']) as $bundle_name => $bundle_instances) {
         foreach ($bundle_instances as $instance_name => $instance_info) {
             $field_info = field_info_field($instance_name);
             foreach ($field_info['columns'] as $column_name => $column_info) {
                 $fields[$instance_name . ':' . $column_name] = t('@label (column @column)', array('@label' => $instance_info['label'], '@column' => $column_name));
             }
         }
     }
     $form['sort']['field'] = array('#type' => 'select', '#title' => t('Sort field'), '#options' => $fields, '#default_value' => isset($field['settings']['handler_settings']['sort']['type']) ? $field['settings']['handler_settings']['sort']['type'] : '', '#states' => array('visible' => array(':input[name="field[settings][handler_settings][sort][type]"]' => array('value' => 'field'))));
     $form['sort']['direction'] = array('#type' => 'select', '#title' => t('Sort direction'), '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), '#default_value' => isset($field['settings']['handler_settings']['sort']['direction']) ? $field['settings']['handler_settings']['sort']['direction'] : 'ASC', '#states' => array('invisible' => array(':input[name="field[settings][handler_settings][sort][type]"]' => array('value' => 'none'))));
     return $form;
 }
示例#5
0
 /**
  * Get all instances of the given field
  *
  * @param string $name
  */
 protected function getInstances($name)
 {
     $ret = array();
     foreach (field_info_instances() as $bundles) {
         foreach ($bundles as $instance) {
             if ($instance['field_name'] === $name) {
                 $ret[] = $instance;
             }
         }
     }
     return $ret;
 }
 public function getDependencies(NodeInterface $node, Context $context)
 {
     /* @var $node EntityNode */
     $order = [];
     $bundle = $node->getBundle();
     // First, fields
     $field = [];
     foreach (field_info_instances('node', $bundle) as $instance) {
         $field[] = 'entity.node.' . $bundle . '.field.' . $instance['field_name'];
         $order[] = isset($instance['weight']) ? $instance['weight'] : 0;
     }
     array_multisort($order, $field);
     return $field;
 }
 /**
  * @param string $group
  *   The name of a group. Can be "locators" or "required" only.
  *
  * @return array
  *   If group is "required" that an array with labels of all required fields
  *   will be returned, if "locators" - will return an array with field names,
  *   keyed by label or machine name.
  */
 public static function getUserEntityFields($group = '')
 {
     static $results = [];
     if (empty($results)) {
         // The fields in "locators" array stored by machine name of a field and duplicates by field label.
         foreach (field_info_instances('user', 'user') as $field_name => $definition) {
             $results['locators'][$definition['label']] = $results['locators'][$field_name] = $field_name;
             if ($definition['required']) {
                 $results['required'][$field_name] = $definition['label'];
             }
         }
     }
     return empty($results[$group]) ? $results : $results[$group];
 }
 /**
  * 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;
 }
 /**
  * @param string $entity
  * @param string $bundle
  */
 public function __construct($entity, $bundle = '')
 {
     $this->entity = $entity;
     if (empty($bundle)) {
         $this->bundle = $this->entity;
     }
     // The fields in "locators" array stored by machine name of a field and duplicates by field label.
     foreach (field_info_instances($this->entity, $this->bundle) as $field_name => $definition) {
         $this->fields['locators'][$definition['label']] = $this->fields['locators'][$field_name] = $field_name;
         if ($definition['required']) {
             $this->fields['required'][$field_name] = $definition['label'];
         }
         $this->instances[$field_name] = $definition;
     }
 }
 /**
  * Implements EntityReferenceHandler::settingsForm().
  */
 public static function settingsForm($field, $instance)
 {
     $entity_info = entity_get_info($field['settings']['target_type']);
     // Merge-in default values.
     $field['settings']['handler_settings'] += array('target_bundles' => array(), 'sort' => array('type' => 'none'));
     if (!empty($entity_info['entity keys']['bundle'])) {
         $bundles = array();
         foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
             $bundles[$bundle_name] = $bundle_info['label'];
         }
         $form['target_bundles'] = array('#type' => 'checkboxes', '#title' => t('Target bundles'), '#options' => $bundles, '#default_value' => $field['settings']['handler_settings']['target_bundles'], '#size' => 6, '#multiple' => TRUE, '#description' => t('The bundles of the entity type that can be referenced. Optional, leave empty for all bundles.'), '#element_validate' => array('_entityreference_element_validate_filter'));
     } else {
         $form['target_bundles'] = array('#type' => 'value', '#value' => array());
     }
     $form['sort']['type'] = array('#type' => 'select', '#title' => t('Sort by'), '#options' => array('none' => t("Don't sort"), 'property' => t('A property of the base table of the entity'), 'field' => t('A field attached to this entity')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $field['settings']['handler_settings']['sort']['type']);
     $form['sort']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entityreference-settings')), '#process' => array('_entityreference_form_process_merge_parent'));
     if ($field['settings']['handler_settings']['sort']['type'] == 'property') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('property' => NULL);
         $form['sort']['settings']['property'] = array('#type' => 'select', '#title' => t('Sort property'), '#required' => TRUE, '#options' => drupal_map_assoc($entity_info['schema_fields_sql']['base table']), '#default_value' => $field['settings']['handler_settings']['sort']['property']);
     } elseif ($field['settings']['handler_settings']['sort']['type'] == 'field') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('field' => NULL);
         $fields = array();
         foreach (field_info_instances($field['settings']['target_type']) as $bundle_name => $bundle_instances) {
             foreach ($bundle_instances as $instance_name => $instance_info) {
                 $field_info = field_info_field($instance_name);
                 foreach ($field_info['columns'] as $column_name => $column_info) {
                     $fields[$instance_name . ':' . $column_name] = t('@label (column @column)', array('@label' => $instance_info['label'], '@column' => $column_name));
                 }
             }
         }
         $form['sort']['settings']['field'] = array('#type' => 'select', '#title' => t('Sort field'), '#required' => TRUE, '#options' => $fields, '#default_value' => $field['settings']['handler_settings']['sort']['field']);
     }
     if ($field['settings']['handler_settings']['sort']['type'] != 'none') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('direction' => 'ASC');
         $form['sort']['settings']['direction'] = array('#type' => 'select', '#title' => t('Sort direction'), '#required' => TRUE, '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), '#default_value' => $field['settings']['handler_settings']['sort']['direction']);
     }
     // Provide an option to lock the entity reference to the current revision if
     // the entity supports it.
     if (!empty($entity_info['revision table'])) {
         $form['lock_revision'] = array('#type' => 'checkbox', '#title' => t('Lock the field to the revision of the entity at the time it was referenced.'), '#default_value' => !empty($field['settings']['handler_settings']['lock_revision']) ? TRUE : FALSE, '#description' => t('When this is enabled, the reference will track the latest revision to that entity when this field is saved. This, combined with e.g. the <a href="!url">Workbench Moderation module</a>, can be used to provide limited workflow functionality around the referenced content.', array('!url' => 'http://drupal.org/project/workbench_moderation')));
     }
     return $form;
 }
 /**
  * Implements EntityReferenceHandler::settingsForm().
  */
 public static function settingsForm($field, $instance)
 {
     $entity_info = entity_get_info($field['settings']['target_type']);
     // Merge-in default values.
     $field['settings']['handler_settings'] += array('target_bundles' => array(), 'sort' => array('type' => 'none'));
     if (!empty($entity_info['entity keys']['bundle'])) {
         $bundles = array();
         foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
             $bundles[$bundle_name] = $bundle_info['label'];
         }
         $form['target_bundles'] = array('#type' => 'checkboxes', '#title' => t('Target bundles'), '#options' => $bundles, '#default_value' => $field['settings']['handler_settings']['target_bundles'], '#size' => 6, '#multiple' => TRUE, '#description' => t('The bundles of the entity type that can be referenced. Optional, leave empty for all bundles.'), '#element_validate' => array('_entityreference_element_validate_filter'));
     } else {
         $form['target_bundles'] = array('#type' => 'value', '#value' => array());
     }
     $form['sort']['type'] = array('#type' => 'select', '#title' => t('Sort by'), '#options' => array('none' => t("Don't sort"), 'property' => t('A property of the base table of the entity'), 'field' => t('A field attached to this entity')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $field['settings']['handler_settings']['sort']['type']);
     $form['sort']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entityreference-settings')), '#process' => array('_entityreference_form_process_merge_parent'));
     if ($field['settings']['handler_settings']['sort']['type'] == 'property') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('property' => NULL);
         $form['sort']['settings']['property'] = array('#type' => 'select', '#title' => t('Sort property'), '#required' => TRUE, '#options' => drupal_map_assoc($entity_info['schema_fields_sql']['base table']), '#default_value' => $field['settings']['handler_settings']['sort']['property']);
     } elseif ($field['settings']['handler_settings']['sort']['type'] == 'field') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('field' => NULL);
         $fields = array();
         foreach (field_info_instances($field['settings']['target_type']) as $bundle_name => $bundle_instances) {
             foreach ($bundle_instances as $instance_name => $instance_info) {
                 $field_info = field_info_field($instance_name);
                 foreach ($field_info['columns'] as $column_name => $column_info) {
                     $fields[$instance_name . ':' . $column_name] = t('@label (column @column)', array('@label' => $instance_info['label'], '@column' => $column_name));
                 }
             }
         }
         $form['sort']['settings']['field'] = array('#type' => 'select', '#title' => t('Sort field'), '#required' => TRUE, '#options' => $fields, '#default_value' => $field['settings']['handler_settings']['sort']['field']);
     }
     if ($field['settings']['handler_settings']['sort']['type'] != 'none') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('direction' => 'ASC');
         $form['sort']['settings']['direction'] = array('#type' => 'select', '#title' => t('Sort direction'), '#required' => TRUE, '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), '#default_value' => $field['settings']['handler_settings']['sort']['direction']);
     }
     // Provide options to reference revisions if the entity supports it.
     if (!empty($entity_info['revision table'])) {
         $form['reference_revisions'] = array('#type' => 'checkbox', '#title' => t('Reference revisions'), '#default_value' => !empty($field['settings']['handler_settings']['reference_revisions']), '#description' => t('When this is enabled, the reference will track the current revision at the time it is referenced. When disabled the reference will always point to the newest revision of the entity.'));
         $form['lock_revision'] = array('#type' => 'checkbox', '#title' => t('Lock the revision.'), '#default_value' => !empty($field['settings']['handler_settings']['lock_revision']), '#description' => t('Locks the field to the revision of the entity at the time it was referenced. If this is disabled the revision will be updated each time the referencing entity is saved.'), '#states' => array('visible' => array(':input[name="field[settings][handler_settings][reference_revisions]"]' => array('checked' => TRUE))));
     }
     return $form;
 }
 public static function getFieldHandlers(Entity $entity, $definition = null, $subtype = false)
 {
     $instances = \field_info_instances($entity->type(), $entity->bundle());
     $handlers = array();
     $handled = array();
     foreach ($instances as $field_name => $instance) {
         $handled[] = $field_name;
         if ($handler = self::getFieldHandler($entity->type(), $field_name, $subtype)) {
             $handlers[$field_name] = $handler;
         }
     }
     // Check special fields on the entity.
     $keys = \entity_get_info($entity->type());
     if (array_key_exists('entity keys', $keys)) {
         foreach ($keys['entity keys'] as $standard => $key) {
             $handled[] = $key;
             if ($handler = self::getTypeHandler($entity->type(), $standard, $subtype)) {
                 $handlers[$key] = $handler;
             }
         }
     }
     // Various other fields.
     foreach ($entity->definition as $key => $value) {
         if (array_search($key, $handled) !== false) {
             continue;
         }
         if ($handler = self::getTypeHandler($entity->type(), $key, $subtype)) {
             $handlers[$key] = $handler;
         }
     }
     // Get other fields on the definition.
     if (is_object($definition) || is_array($definition)) {
         foreach ($definition as $key => $value) {
             if (array_search($key, $handled) !== false) {
                 continue;
             }
             if ($handler = self::getTypeHandler($entity->type(), $key, $subtype)) {
                 $handlers[$key] = $handler;
             }
         }
     }
     return $handlers;
 }
 /**
  * Implements EntityReferenceHandler::settingsForm().
  */
 public static function settingsForm($field, $instance)
 {
     $entity_info = entity_get_info($field['settings']['target_type']);
     // Merge-in default values.
     $field['settings']['handler_settings'] += array('target_bundles' => array(), 'sort' => array('type' => 'none'));
     if (!empty($entity_info['entity keys']['bundle'])) {
         $bundles = array();
         foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
             $bundles[$bundle_name] = $bundle_info['label'];
         }
         $form['target_bundles'] = array('#type' => 'checkboxes', '#title' => t('Target bundles'), '#options' => $bundles, '#default_value' => $field['settings']['handler_settings']['target_bundles'], '#size' => 6, '#multiple' => TRUE, '#description' => t('The bundles of the entity type that can be referenced. Optional, leave empty for all bundles.'), '#element_validate' => array('_entityreference_element_validate_filter'));
     } else {
         $form['target_bundles'] = array('#type' => 'value', '#value' => array());
     }
     $form['sort']['type'] = array('#type' => 'select', '#title' => t('Sort by'), '#options' => array('none' => t("Don't sort"), 'property' => t('A property of the base table of the entity'), 'field' => t('A field attached to this entity')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $field['settings']['handler_settings']['sort']['type']);
     $form['sort']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entityreference-settings')), '#process' => array('_entityreference_form_process_merge_parent'));
     if ($field['settings']['handler_settings']['sort']['type'] == 'property') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('property' => NULL);
         $form['sort']['settings']['property'] = array('#type' => 'select', '#title' => t('Sort property'), '#required' => TRUE, '#options' => drupal_map_assoc($entity_info['schema_fields_sql']['base table']), '#default_value' => $field['settings']['handler_settings']['sort']['property']);
     } elseif ($field['settings']['handler_settings']['sort']['type'] == 'field') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('field' => NULL);
         $fields = array();
         foreach (field_info_instances($field['settings']['target_type']) as $bundle_name => $bundle_instances) {
             foreach ($bundle_instances as $instance_name => $instance_info) {
                 $field_info = field_info_field($instance_name);
                 foreach ($field_info['columns'] as $column_name => $column_info) {
                     $fields[$instance_name . ':' . $column_name] = t('@label (column @column)', array('@label' => $instance_info['label'], '@column' => $column_name));
                 }
             }
         }
         $form['sort']['settings']['field'] = array('#type' => 'select', '#title' => t('Sort field'), '#required' => TRUE, '#options' => $fields, '#default_value' => $field['settings']['handler_settings']['sort']['field']);
     }
     if ($field['settings']['handler_settings']['sort']['type'] != 'none') {
         // Merge-in default values.
         $field['settings']['handler_settings']['sort'] += array('direction' => 'ASC');
         $form['sort']['settings']['direction'] = array('#type' => 'select', '#title' => t('Sort direction'), '#required' => TRUE, '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), '#default_value' => $field['settings']['handler_settings']['sort']['direction']);
     }
     return $form;
 }
 /**
  * Generate a settings form for this handler.
  */
 public function settingsForm($field, $instance)
 {
     // Current settings.
     $settings = $instance['settings']['behaviors']['autofill'];
     $widget = $instance['widget'];
     // Load available fields from instance bundle.
     $entity_type = $instance['entity_type'];
     $bundle_name = $instance['bundle'];
     $bundle_info = field_info_instances($entity_type, $bundle_name);
     // Field target metadata.
     $field_map = field_info_field_map();
     $target_type = $field['settings']['target_type'];
     $target_bundles = isset($field['settings']['handler_settings']['target_bundles']);
     $target_bundles = $target_bundles ? $field['settings']['handler_settings']['target_bundles'] : array();
     // Skip autofill for the reference field.
     unset($bundle_info[$field['field_name']]);
     // Create checkboxes options for available fields.
     $field_options = array();
     foreach ($bundle_info as $field_name => $field_info) {
         if (!empty($field_map[$field_name]['bundles'][$target_type])) {
             $available_bundles = $field_map[$field_name]['bundles'][$target_type];
             // Determine all targeted bundles that use this field.
             $option_bundles = empty($target_bundles) ? $available_bundles : array_intersect($target_bundles, $available_bundles);
             if (!empty($option_bundles)) {
                 $field_options[$field_name] = t('@field_label (@field_name): <em>Available in bundle(s) @bundles</em>', array('@field_label' => $field_info['label'], '@field_name' => $field_name, '@bundles' => implode(', ', $option_bundles)));
             }
         }
     }
     $form['overwrite'] = array('#type' => 'checkbox', '#title' => t('Overwrite existing data'), '#description' => t('Select if you want to overwrite fields that already have values. <br/><em><strong>NOTE:</strong> Disabling this is experimental and might not work 100%. If you experience issues with fields being overridden nonetheless, please report what field type and settings this occurs on in the modules issue queue on drupal.org</em>'), '#default_value' => isset($settings['overwrite']) ? $settings['overwrite'] : 1);
     if (empty($field_options)) {
         $no_fields_found = t('There are no common fields between this bundle and its referenced entities.');
         $usage_instructions = t('To use autofill, you need to add instances of the same fields to its referenced bundles.');
         $form['no_fields'] = array('#markup' => '<div class="messages warning">' . $no_fields_found . $usage_instructions . '</div>', '#type' => 'item');
     } else {
         $form['fields'] = array('#type' => 'checkboxes', '#title' => t('Fields'), '#options' => $field_options, '#description' => t('Select which fields from the referenced entity you want to load on changing the value of this field.'), '#default_value' => isset($settings['fields']) ? $settings['fields'] : array());
     }
     return $form;
 }
/**
 * Implements hook_form().
 */
function workflow_transition_extra_form($form, &$form_state, $name)
{
    $workflow = workflow_load_by_name($name);
    $form_state['workflow'] = $workflow;
    $fields = workflow_transition_extra_get_workable_fields();
    $options = array('-- none --');
    foreach ($fields as $key => $fields) {
        list($type, $bundle) = explode(':', $key);
        foreach ($fields as $field) {
            $instance = field_info_instances($type, $bundle);
            $label = $instance[$field['field_name']]['label'];
            $options[$field['field_name']] = "{$label} - {$field['field_name']}";
        }
    }
    $states = $workflow->states;
    $form['transitions'] = array('#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Select entityreference field contain user allowed to change state.'));
    foreach ($workflow->transitions as $transition) {
        $label = $workflow->states[$transition->sid]->name . ' --> ' . $workflow->states[$transition->target_sid]->name;
        $key = implode(':', array($transition->sid, $transition->target_sid));
        $form['transitions'][$key] = array('#title' => $label, '#type' => 'select', '#options' => $options, '#default_value' => @isset($workflow->options['transitions_extra'][$key]) ? $workflow->options['transitions_extra'][$key] : NULL);
    }
    $form['actions'] = array('#type' => 'actions', 'actions' => ['submit' => ['#type' => 'submit', '#value' => t('Submit')]]);
    return $form;
}
示例#16
0
/**
 * Delete all field data for an entity.
 *
 * This hook is invoked from field_attach_delete() to ask the field storage
 * module to delete field data.
 *
 * @param $entity_type
 *   The entity type of entity, such as 'node' or 'user'.
 * @param $entity
 *   The entity on which to operate.
 * @param $fields
 *   An array listing the fields to delete. The keys and values of the
 *   array are field IDs.
 */
function hook_field_storage_delete($entity_type, $entity, $fields)
{
    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
    foreach (field_info_instances($entity_type, $bundle) as $instance) {
        if (isset($fields[$instance['field_id']])) {
            $field = field_info_field_by_id($instance['field_id']);
            field_sql_storage_field_storage_purge($entity_type, $entity, $field, $instance);
        }
    }
}
  /**
   * Helper method to get all the displayed fields for a bundle and a view_mode.
   *
   * @param string $view_mode
   *   The view mode.
   *
   * @return array
   *   An array of field names that are displayed in this view mode.
   */
  protected function displayedFieldsList($view_mode) {
    $entity_field_instances = field_info_instances($this->entityType);
    $bundle_field_instances = reset($entity_field_instances);
    if ($bundle = $this->bundle) {
      $bundle_field_instances = $entity_field_instances[$bundle];
    }
    // Traverse the field instance to get all non hidden fields.
    $displayed_fields = array_map(function ($field_instance) use ($view_mode) {
      if (empty($field_instance['display'][$view_mode]) || $field_instance['display'][$view_mode]['type'] == 'hidden' || $field_instance['deleted']) {
        return NULL;
      }
      return $field_instance['field_name'];
    }, $bundle_field_instances);

    // Remove all NULL fields.
    return array_filter(array_values($displayed_fields));
  }
function build_type_field_list($type)
{
    $names = field_info_instances('node', $type);
    $test = array();
    foreach ($names as $key) {
        $test[$key['field_name']] = $key['field_name'];
    }
    return $test;
}
 public static function getTypes($type = null)
 {
     return field_info_instances($type);
 }
示例#20
0
function epf_preprocess_node(&$variables)
{
    $node = $variables['node'];
    list(, , $bundle) = entity_extract_ids('node', $node);
    $output = '';
    // $variables['ins']=$variables['content']['links'];
    foreach (field_info_instances('node', $bundle) as $instance) {
        if ($instance['field_name'] == 'authorname') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['paper_authors'] = $node->{$instance['field_name']}['und'][0]['value'];
            }
        }
        if ($instance['field_name'] == 'field_reviewer') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['reviewer'] = $node->{$instance['field_name']}['und'][0]['value'];
            }
        }
        if ($instance['field_name'] == 'datebegin') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['datebegin'] = substr($node->{$instance['field_name']}['und'][0]['value'], 0, 10);
            }
        }
        if ($instance['field_name'] == 'dateend') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['dateend'] = substr($node->{$instance['field_name']}['und'][0]['value'], 0, 10);
            }
        }
        if ($instance['field_name'] == 'city') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['city'] = $node->{$instance['field_name']}['und'][0]['value'];
            }
        }
        if ($instance['field_name'] == 'website') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['website'] = $node->{$instance['field_name']}['und'][0]['value'];
            }
        }
        if ($instance['widget']['module'] == 'arxiv') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['paper_authors'] = $node->{$instance['field_name']}['und'][0]['authors'];
            }
            if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['pdfUrl'] != '') {
                $output .= '<a href="' . url('/paper/download/' . $node->nid . '/pdf') . '" >pdf </a>';
            }
            if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['psUrl'] != '') {
                $output .= '<a href="' . url('/paper/download/' . $node->nid . '/ps') . '" >ps </a>';
            }
            if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['otherUrl'] != '') {
                $output .= '<a href="' . url('/paper/download/' . $node->nid . '/other') . '" >other </a>';
            }
        }
        if ($instance['field_name'] == 'field_author') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['paper_authors'] = $node->{$instance['field_name']}['und'][0]['value'];
            }
        }
        if ($instance['field_name'] == 'field_upload') {
            if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['filename'] != '') {
                $url = file_create_url($node->{$instance['field_name']}['und'][0]['uri']);
                $output .= '<a href="' . url('/paper/download/' . $node->nid) . '" >download </a>';
            }
        }
        if ($instance['field_name'] == 'field_prefix') {
            if (!empty($node->{$instance['field_name']})) {
                $variables['news_prefix'] = $node->{$instance['field_name']}['und'][0]['value'];
            }
        }
    }
    if (substr($node->type, 0, 5) == 'paper') {
        $statistics = statistics_get($node->nid);
        $obj = db_select('arxiv_downNo', 'm')->fields('m', array('downloadNo'))->condition('m.nid', $node->nid)->execute()->fetchAll();
        if ($obj) {
            $variables['download'] = $output . ' (' . (empty($statistics['totalcount']) ? 0 : $statistics['totalcount']) . ' views, ' . $obj[0]->downloadNo . ' download, ' . $node->comment_count . ' comments)';
        } else {
            $variables['download'] = $output . ' (' . (empty($statistics['totalcount']) ? 0 : $statistics['totalcount']) . ' views, 0 download, ' . $node->comment_count . ' comments)';
        }
    }
    if ($variables['page']) {
        $variables['submitted'] = t('posted on !datetime', array('!datetime' => $variables['date']));
    } else {
        $variables['submitted'] = t('posted by !username, !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
    }
}
示例#21
0
/**
 * Return fields to be added when creating a new display with the panels editor.
 */
function hook_ds_panels_default_fields($entity_type, $bundle, $view_mode)
{
    // Get the fields from Field API.
    $fields = field_info_instances($entity_type, $bundle);
    return $fields;
}
示例#22
0
/**
 * Allow altering fields automatically added to Entityform Views.
 *
 * entityform_settings will already have been added to the current View Display.
 * @see _entityform_view_add_all_fields().
 * @param $autofields
 *  Array of fields that will be added
 * @param $view
 * @param $display_id
 */
function hook_entityform_views_autofields_alter(&$autofields, $view, $display_id)
{
    $view_entityform_settings = $view->display[$display_id]->entityform_settings;
    $instances = field_info_instances('entityform', $view_entityform_settings['entityform_type']);
    $view_mode = $view_entityform_settings['view_mode'];
    foreach ($autofields as &$autofield) {
        //Check to see this field was added by entityform
        if ($instances[$autofield['field_name']]) {
            $field = $instances[$autofield['field_name']];
            if ($label = _entityform_view_label_get_label($field, $view_mode)) {
                $autofield['options']['label'] = $label;
            }
        }
    }
}
 /**
  * Create a user with a particular role.
  *
  * @param array|string $role_names
  *   String role or array of role names to assign to user. Note that the user
  *   always has the default permissions derived from the "authenticated users"
  *   role.
  * @param string $password
  *   Preferred password to set for the user.
  * @param array $edit_overrides
  *   Values for user or user profile fields to override.
  *
  * @return object|bool
  *   A fully loaded user object with pass_raw property, or FALSE if account
  *   creation fails.
  */
 protected function drupalCreateUserWithRoles($role_names = [], $password = NULL, $edit_overrides = [])
 {
     // Create a user assigned to that role.
     $edit = [];
     $edit['mail'] = Random::email();
     $edit['name'] = $edit['mail'];
     $edit['pass'] = is_null($password) ? user_password() : $password;
     $edit['status'] = 1;
     $edit['roles'] = [];
     if (!empty($role_names)) {
         $role_names = is_array($role_names) ? $role_names : [$role_names];
         foreach ($role_names as $rolename) {
             $role = user_role_load_by_name($rolename);
             $edit['roles'][$role->rid] = $role->name;
         }
     }
     // Merge fields with provided $edit_overrides.
     $edit_overrides = array_merge($edit, $edit_overrides);
     // Build an empty user object, including all default fields.
     $account = drupal_anonymous_user();
     $account->roles = array_merge($account->roles, $edit_overrides['roles']);
     foreach (field_info_instances('user', 'user') as $field_name => $info) {
         if (!isset($account->{$field_name})) {
             $account->{$field_name} = [];
         }
     }
     $account = user_save($account, $edit_overrides);
     if (empty($account->uid)) {
         return FALSE;
     }
     $account->pass_raw = $edit_overrides['pass'];
     $this->assertTrue(!empty($account->uid), t('User created with name %name (%uid) and pass %pass and roles %roles', ['%roles' => implode(', ', $role_names), '%name' => $edit['name'], '%uid' => $account->uid, '%pass' => $edit['pass']]), t('User login'));
     return $account;
 }
 /**
  * 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);
     }
 }
  /**
   * Build the part of the form that allows the user to select the view's filters.
   *
   * By default, this adds "of type" and "tagged with" filters (when they are
   * available).
   */
  protected function build_filters(&$form, &$form_state) {
    // Find all the fields we are allowed to filter by.
    $fields = views_fetch_fields($this->base_table, 'filter');

    $entity_info = $this->entity_info;
    // If the current base table support bundles and has more than one (like user).
    if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) {
      // Get all bundles and their human readable names.
      $options = array('all' => t('All'));
      foreach ($entity_info['bundles'] as $type => $bundle) {
        $options[$type] = $bundle['label'];
      }
      $form['displays']['show']['type'] = array(
        '#type' => 'select',
        '#title' => t('of type'),
        '#options' => $options,
      );
      $selected_bundle = views_ui_get_selected($form_state, array('show', 'type'), 'all', $form['displays']['show']['type']);
      $form['displays']['show']['type']['#default_value'] = $selected_bundle;
      // Changing this dropdown updates the entire content of $form['displays']
      // via AJAX, since each bundle might have entirely different fields
      // attached to it, etc.
      views_ui_add_ajax_trigger($form['displays']['show'], 'type', array('displays'));
    }

    // Check if we are allowed to filter by taxonomy, and if so, add the
    // "tagged with" filter to the view.
    //
    // We construct this filter using taxonomy_index.tid (which limits the
    // filtering to a specific vocabulary) rather than taxonomy_term_data.name
    // (which matches terms in any vocabulary). This is because it is a more
    // commonly-used filter that works better with the autocomplete UI, and
    // also to avoid confusion with other vocabularies on the site that may
    // have terms with the same name but are not used for free tagging.
    //
    // The downside is that if there *is* more than one vocabulary on the site
    // that is used for free tagging, the wizard will only be able to make the
    // "tagged with" filter apply to one of them (see below for the method it
    // uses to choose).
    if (isset($fields['taxonomy_index.tid'])) {
      // Check if this view will be displaying fieldable entities.
      if (!empty($entity_info['fieldable'])) {
        // Find all "tag-like" taxonomy fields associated with the view's
        // entities. If a particular entity type (i.e., bundle) has been
        // selected above, then we only search for taxonomy fields associated
        // with that bundle. Otherwise, we use all bundles.
        $bundles = array_keys($entity_info['bundles']);
        // Double check that this is a real bundle before using it (since above
        // we added a dummy option 'all' to the bundle list on the form).
        if (isset($selected_bundle) && in_array($selected_bundle, $bundles)) {
          $bundles = array($selected_bundle);
        }
        $tag_fields = array();
        foreach ($bundles as $bundle) {
          foreach (field_info_instances($this->entity_type, $bundle) as $instance) {
            // We define "tag-like" taxonomy fields as ones that use the
            // "Autocomplete term widget (tagging)" widget.
            if ($instance['widget']['type'] == 'taxonomy_autocomplete') {
              $tag_fields[] = $instance['field_name'];
            }
          }
        }
        $tag_fields = array_unique($tag_fields);
        if (!empty($tag_fields)) {
          // If there is more than one "tag-like" taxonomy field available to
          // the view, we can only make our filter apply to one of them (as
          // described above). We choose 'field_tags' if it is available, since
          // that is created by the Standard install profile in core and also
          // commonly used by contrib modules; thus, it is most likely to be
          // associated with the "main" free-tagging vocabulary on the site.
          if (in_array('field_tags', $tag_fields)) {
            $tag_field_name = 'field_tags';
          }
          else {
            $tag_field_name = reset($tag_fields);
          }
          // Add the autocomplete textfield to the wizard.
          $form['displays']['show']['tagged_with'] = array(
            '#type' => 'textfield',
            '#title' => t('tagged with'),
            '#autocomplete_path' => 'taxonomy/autocomplete/' . $tag_field_name,
            '#size' => 30,
            '#maxlength' => 1024,
            '#field_name' => $tag_field_name,
            '#element_validate' => array('views_ui_taxonomy_autocomplete_validate'),
          );
        }
      }
    }
  }
 /**
  * Get the Transition's $field_info.
  *
  * This is called in hook_cron, to get the $field_info.
  * @todo: read $field_name directly from table.
  */
 public function getWorkflowItem()
 {
     $workflow_item = NULL;
     if (!empty($this->field_name)) {
         // @todo: read $field_name directly from table.
     }
     $entity_type = $this->entity_type;
     $entity = $this->getEntity();
     $entity_bundle = $this->getEntity()->type;
     foreach (field_info_instances($entity_type, $entity_bundle) as $field_name => $field_instance) {
         $field_info = field_info_field($field_instance['field_name']);
         $field_type = $field_info['type'];
         if ($field_type == 'workflow') {
             // Set cache.
             $this->field_name = $field_name;
             // Prepare return value.
             $workflow_item = new WorkflowItem($field_info, $field_instance, $entity_type, $this->getEntity());
         }
     }
     return $workflow_item;
 }
 /**
  * Provide a default display for newly panelized entities.
  *
  * This should be implemented by the entity plugin.
  */
 function get_default_display($bundle, $view_mode)
 {
     // This is a straight up empty display.
     $display = panels_new_display();
     $display->layout = 'flexible';
     $panes = array();
     foreach (field_info_instances($this->entity_type, $bundle) as $field_name => $instance) {
         $view_mode_settings = field_view_mode_settings($this->entity_type, $bundle);
         $actual_mode = !empty($view_mode_settings[$view_mode]['custom_settings']) ? $view_mode : 'default';
         $field_display = $instance['display'][$actual_mode];
         $pane = panels_new_pane('entity_field', $this->entity_type . ':' . $field_name, TRUE);
         $pane->configuration['formatter'] = $field_display['type'];
         $pane->configuration['formatter_settings'] = $field_display['settings'];
         $pane->configuration['label'] = $field_display['label'];
         $pane->configuration['context'] = 'panelizer';
         $panes[] = array('#pane' => $pane, '#weight' => $field_display['weight']);
     }
     // Use our #weights to sort these so they appear in whatever order the
     // normal field configuration put them in.
     uasort($panes, 'element_sort');
     foreach ($panes as $pane) {
         $display->add_pane($pane['#pane'], 'center');
     }
     return $display;
 }
 public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false)
 {
     /* @var $node ViewNode */
     $entityType = $node->getEntityType();
     $bundle = $node->getBundle();
     $name = $node->getName();
     // First populate the variable that will be used during the
     // hook_entity_info_alter() call to populate the view modes
     $viewModes = variable_get(USYNC_VAR_VIEW_MODE, []);
     $viewModes[$entityType][$name] = $name;
     variable_set(USYNC_VAR_VIEW_MODE, $viewModes);
     // First grab a list of everything that can be displayed in view
     // modes with both extra fields and real fields
     $instances = field_info_instances($entityType, $bundle);
     $bundleSettings = field_bundle_settings($entityType, $bundle);
     $extra = $this->getExtraFieldsDisplay($entityType, $bundle);
     $weight = 0;
     $displayExtra = [];
     $displayField = [];
     // Then deal with fields and such
     foreach ($node->getValue() as $propertyName => $formatter) {
         if (isset($instances[$propertyName])) {
             $display = array();
             // We are working with a field
             if (!is_array($formatter)) {
                 if (true === $formatter || 'default' === $formatter) {
                     $formatter = array();
                 } else {
                     if (false === $formatter || null === $formatter || 'delete' === $formatter) {
                         continue;
                     } else {
                         if (!is_string($formatter)) {
                             $context->logWarning(sprintf("%s: %s invalid value for formatter", $node->getPath(), $propertyName));
                             $formatter = array();
                         } else {
                             $display['type'] = $formatter;
                         }
                     }
                 }
             } else {
                 $display = $formatter;
             }
             // Merge default and save
             $displayField[$propertyName] = drupal_array_merge_deep($this->getFieldDefault($node, $entityType, $bundle, $propertyName, $context), $display, array('weight' => $weight++));
         } else {
             if (isset($extra[$propertyName])) {
                 // We are working with and extra field
                 if (!is_array($formatter)) {
                     if (true === $formatter || 'default' === $formatter) {
                         $formatter = array();
                     } else {
                         if (false === $formatter || null === $formatter || 'delete' === $formatter) {
                             continue;
                         } else {
                             $context->logWarning(sprintf("%s: %s extra fields can only be delete or default", $node->getPath(), $propertyName));
                         }
                     }
                 }
                 // Merge default and save
                 $displayExtra[$propertyName] = ['visible' => true, 'weight' => $weight++];
             } else {
                 $context->logError(sprintf("%s: %s property is nor a field nor an extra field", $node->getPath(), $propertyName));
             }
         }
     }
     // Iterate over the fields and update each instance: we don't
     // need to do it with the $displayExtra property since it is
     // already the correctly formatted variable
     foreach ($displayField as $fieldName => $display) {
         $instances[$fieldName]['display'][$name] = $display;
     }
     // Remove non configured fields and extra fields from display
     foreach ($instances as $fieldName => $instance) {
         if (!isset($displayField[$fieldName])) {
             $instance['display'][$name] = array('type' => 'hidden');
         }
         if ($dirtyAllowed) {
             $data = $instance;
             unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']);
             db_update('field_config_instance')->condition('id', $instance['id'])->fields(['data' => serialize($data)])->execute();
         } else {
             field_update_instance($instance);
         }
     }
     foreach (array_keys($extra) as $propertyName) {
         if (isset($displayExtra[$propertyName])) {
             $bundleSettings['extra_fields']['display'][$propertyName][$name] = $displayExtra[$propertyName];
         } else {
             $bundleSettings['extra_fields']['display'][$propertyName][$name] = ['visible' => false, 'weight' => $weight++];
         }
     }
     $bundleSettings['view_modes'][$name] = ['label' => $name, 'custom_settings' => true];
     if ($dirtyAllowed) {
         // Hopefully nothing about display is really cached into the
         // internal field cache class, except the raw display array
         // into each instance, but nothing will use that except this
         // specific view mode implementation, we are going to delay
         // a few cache clear calls at the very end of the processing.
         // From field_bundle_settings().
         variable_set('field_bundle_settings_' . $entityType . '__' . $bundle, $bundleSettings);
     } else {
         field_bundle_settings($entityType, $bundle, $bundleSettings);
     }
     if ($dirtyAllowed) {
         // From field_update_instance()
         cache_clear_all('*', 'cache_field', true);
         // From field_info_cache_clear()
         drupal_static_reset('field_view_mode_settings');
         // We need to clear cache in order for later view modes to
         // load the right instance and prevent them for overriding
         // what we actually did here
         entity_info_cache_clear();
         _field_info_field_cache()->flush();
     }
 }
 /**
  *  @method:
  *    Process all list of nodes.
  *
  *    This is where all the fields are handled
  */
 private function _parse_nodes(&$nodes = array())
 {
     global $base_url;
     //does for each for each of the node types
     foreach ($nodes as $type => $values) {
         $fields = field_info_instances("node", $type);
         //does for each of the nodes
         foreach ($values as $node => $node_values) {
             //loads all scribe attachment
             $scribe = entity_load('scribe_attachment', FALSE, array('entity_id' => $node_values->nid));
             $nodes[$type][$node]->scribe = $scribe;
             //does for each of the field
             foreach ($fields as $field_name => $field_value) {
                 $field_items = field_get_items('node', $node_values, $field_name);
                 if (!empty($field_items)) {
                     //does for each of them.
                     foreach ($field_items as $item => $item_value) {
                         switch ($field_value['field_name']) {
                             case 'og_group_ref':
                                 break;
                                 //makes the images relative to the node
                             //makes the images relative to the node
                             case 'field_image':
                             case 'field_timeline_media_image':
                                 if (!isset($item_value['fid'])) {
                                     break;
                                 }
                                 //changes over to allow the image refence to use the same formatting
                                 $item_value['target_id'] = $item_value['fid'];
                             case 'field_image_references':
                                 //conversion to relative path for images
                                 if (isset($item_value['target_id'])) {
                                     $fid = (int) $item_value['target_id'];
                                     $file = file_load($fid);
                                     //only does this for the file if its not empty
                                     if (!empty($file)) {
                                         $file->server_path = drupal_realpath($file->uri);
                                         $file->relative_path = str_replace('public:/', variable_get('file_public_path', 'sites/default/files'), $file->uri);
                                         $field_items[$item] = (array) $file;
                                         $this->include_images[] = $file->server_path;
                                     }
                                 }
                                 break;
                             case 'field_reference':
                                 break;
                                 //handler for the body section
                             //handler for the body section
                             case 'body':
                                 //variables
                                 $body_value = $item_value['value'];
                                 //does for the following attribtes
                                 $this->_add_images_regex('href', $body_value);
                                 $this->_add_images_regex('src', $body_value);
                                 //does a simple replacement from the domain
                                 $field_items[$item]['value'] = str_replace($base_url, '', $field_items[$item]['value']);
                                 $field_items[$item]['safe_value'] = str_replace($base_url, '', $field_items[$item]['safe_value']);
                                 break;
                         }
                         $nodes[$type][$node]->{$field_name} = $field_items;
                     }
                 }
             }
         }
     }
 }
 /**
  * Builds and inserts taxonomy index entries for a given node.
  *
  * The index lists all terms that are related to a given node entity, and is
  * therefore maintained at the entity level.
  *
  * @param $node
  *   The node object.
  *
  * @see taxonomy_build_node_index()
  */
 protected function buildNodeIndex($node)
 {
     // We maintain a denormalized table of term/node relationships, containing
     // only data for current, published nodes.
     $status = NULL;
     if (variable_get('taxonomy_maintain_index_table', TRUE)) {
         // If a node property is not set in the node object when node_save() is
         // called, the old value from $node->original is used.
         if (!empty($node->original)) {
             $status = (int) (!empty($node->status) || !isset($node->status) && !empty($node->original->status));
             $sticky = (int) (!empty($node->sticky) || !isset($node->sticky) && !empty($node->original->sticky));
         } else {
             $status = (int) (!empty($node->status));
             $sticky = (int) (!empty($node->sticky));
         }
     }
     // We only maintain the taxonomy index for published nodes.
     if ($status) {
         // Collect a unique list of all the term IDs from all node fields.
         $tid_all = array();
         foreach (field_info_instances('node', $node->type) as $instance) {
             $field_name = $instance['field_name'];
             $field = field_info_field($field_name);
             if (!empty($field['settings']['target_type']) && $field['settings']['target_type'] == 'taxonomy_term' && $field['storage']['type'] == 'field_sql_storage') {
                 // If a field value is not set in the node object when node_save() is
                 // called, the old value from $node->original is used.
                 if (isset($node->{$field_name})) {
                     $items = $node->{$field_name};
                 } elseif (isset($node->original->{$field_name})) {
                     $items = $node->original->{$field_name};
                 } else {
                     continue;
                 }
                 foreach (field_available_languages('node', $field) as $langcode) {
                     if (!empty($items[$langcode])) {
                         foreach ($items[$langcode] as $item) {
                             $tid_all[$item['target_id']] = $item['target_id'];
                         }
                     }
                 }
             }
             // Re-calculate the terms added in taxonomy_build_node_index() so
             // we can optimize database queries.
             $original_tid_all = array();
             if ($field['module'] == 'taxonomy' && $field['storage']['type'] == 'field_sql_storage') {
                 // If a field value is not set in the node object when node_save() is
                 // called, the old value from $node->original is used.
                 if (isset($node->{$field_name})) {
                     $items = $node->{$field_name};
                 } elseif (isset($node->original->{$field_name})) {
                     $items = $node->original->{$field_name};
                 } else {
                     continue;
                 }
                 foreach (field_available_languages('node', $field) as $langcode) {
                     if (!empty($items[$langcode])) {
                         foreach ($items[$langcode] as $item) {
                             $original_tid_all[$item['tid']] = $item['tid'];
                         }
                     }
                 }
             }
         }
         // Insert index entries for all the node's terms, that were not
         // already inserted in taxonomy_build_node_index().
         $tid_all = array_diff($tid_all, $original_tid_all);
         // Insert index entries for all the node's terms.
         if (!empty($tid_all)) {
             $query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created'));
             foreach ($tid_all as $tid) {
                 $query->values(array('nid' => $node->nid, 'tid' => $tid, 'sticky' => $sticky, 'created' => $node->created));
             }
             $query->execute();
         }
     }
 }