/**
  * 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;
 }
 /**
  * Overrides ResourceEntity::publicFields().
  */
 public function publicFields()
 {
     $public_fields = parent::publicFields();
     $public_fields['body'] = array('property' => 'body', 'sub_property' => 'value');
     // By checking that the field exists, we allow re-using this class on
     // different tests, where different fields exist.
     if (field_info_field('entity_reference_single')) {
         $public_fields['entity_reference_single'] = array('property' => 'entity_reference_single', 'resource' => array('name' => 'test_articles', 'majorVersion' => 1, 'minorVersion' => 2));
     }
     if (field_info_field('entity_reference_multiple')) {
         $public_fields['entity_reference_multiple'] = array('property' => 'entity_reference_multiple', 'resource' => array('name' => 'test_articles', 'majorVersion' => 1, 'minorVersion' => 2));
     }
     if (field_info_field('integer_single')) {
         $public_fields['integer_single'] = array('property' => 'integer_single');
     }
     if (field_info_field('integer_multiple')) {
         $public_fields['integer_multiple'] = array('property' => 'integer_multiple');
     }
     if (variable_get('restful_test_reference_simple')) {
         $public_fields['user'] = array('property' => 'author');
         if (variable_get('restful_test_reference_resource')) {
             $public_fields['user']['resource'] = array('name' => 'users', 'majorVersion' => 1, 'minorVersion' => 0);
         }
     }
     return $public_fields;
 }
 protected function queryLoad($ids)
 {
     $multifields = multifield_get_fields();
     foreach (array_keys($multifields) as $field_name) {
         $query = new EntityFieldQuery();
         if ($ids) {
             $query->fieldCondition($field_name, 'id', $ids, 'IN');
         } else {
             $query->fieldCondition($field_name, 'id', 0, '>');
         }
         if ($results = $query->execute()) {
             $pseudo_entities = array();
             $field = field_info_field($field_name);
             foreach ($results as $entity_type => $entities) {
                 // Simply doing an entity load on the entities with multifield values
                 // will cause the cacheSet() from multifield_field_load() to get
                 // invoked.
                 $entities = entity_load($entity_type, array_keys($entities));
                 foreach ($entities as $entity) {
                     if ($items = field_get_items($entity_type, $entity, $field_name)) {
                         foreach ($items as $item) {
                             $pseudo_entities[$item['id']] = _multifield_field_item_to_entity($field['type'], $item);
                         }
                     }
                 }
             }
             $this->cacheSet($pseudo_entities);
         }
     }
     return array_intersect_key($this->entityCache, drupal_map_assoc($ids, $ids));
 }
 /**
  * {@inheritdoc}
  */
 public function preprocess($value)
 {
     // Text field. Check if field has an input format.
     $field_info = field_info_field($this->getProperty());
     // If there was no bundle that had the field instance, then return NULL.
     if (!($instance = field_info_instance($this->getEntityType(), $this->getProperty(), $this->getBundle()))) {
         return NULL;
     }
     $return = NULL;
     if ($field_info['cardinality'] == 1) {
         // Single value.
         if (!$instance['settings']['text_processing']) {
             return $value;
         }
         return array('value' => $value, 'format' => 'filtered_html');
     }
     // Multiple values.
     foreach ($value as $delta => $single_value) {
         if (!$instance['settings']['text_processing']) {
             $return[$delta] = $single_value;
         } else {
             $return[$delta] = array('value' => $single_value, 'format' => 'filtered_html');
         }
     }
     return $return;
 }
function bunsen_field_attach_view_alter(&$output, $context)
{
    // We proceed only on nodes.
    if ($context['entity_type'] != 'node' || $context['view_mode'] != 'full') {
        return;
    }
    $node = $context['entity'];
    // Load all instances of the fields for the node.
    $instances = _field_invoke_get_instances('node', $node->type, array('default' => TRUE, 'deleted' => FALSE));
    foreach ($instances as $field_name => $instance) {
        // Only work with fields that we display or that have empty values
        $access = !empty($output[$field_name]['#access']) ? $output[$field_name]['#access'] : FALSE;
        if ($access || empty($node->{$field_name})) {
            // Set content for fields if they are empty.
            if (empty($node->{$field_name})) {
                $display = field_get_display($instance, 'full', $node);
                // Do not add field that is hidden in current display.
                if ($display['type'] == 'hidden') {
                    continue;
                }
                // Load field settings.
                $field = field_info_field($field_name);
                // Set output for field.
                $output[$field_name] = array('#theme' => 'field', '#title' => $instance['label'], '#label_display' => 'above', '#field_type' => $field['type'], '#field_name' => $field_name, '#bundle' => $node->type, '#object' => $node, '#items' => array(array()), '#entity_type' => 'node', '#weight' => $display['weight'], 0 => array('#markup' => ''));
            }
        }
    }
}
Esempio n. 6
0
 public function build()
 {
     $type = self::guessType($this->type);
     if (!($info = field_info_field($this->name))) {
         field_create_field(array('field_name' => $this->name, 'type' => $type, 'module' => ''));
     }
 }
 /**
  * Implements EditEntityFieldAccessCheckInterface::accessEditEntityField().
  */
 public function accessEditEntityField($entity_type, $entity, $field_name)
 {
     $is_extra_field = _quickedit_is_extra_field($entity_type, $field_name);
     $entity_access = entity_access('update', $entity_type, $entity);
     $field_access = $is_extra_field ? TRUE : field_access('edit', field_info_field($field_name), $entity_type, $entity);
     return $entity_access && $field_access;
 }
 protected function getFieldDefault(NodeInterface $node, $entityType, $bundle, $fieldName, Context $context)
 {
     /* @var $node ViewNode */
     $entityType = $node->getEntityType();
     $bundle = $node->getBundle();
     $default = array('type' => 'hidden', 'label' => 'hidden', 'settings' => array());
     if (!($field = field_info_field($fieldName))) {
         // @todo Should we warn? This is surely an extra field.
         return $default;
     }
     if (!($field = field_info_field_types($field['type']))) {
         $context->logError("%s: %s field type does not exist", $node->getPath(), $field['types']);
         return $default;
     }
     $formatter = null;
     if (!empty($field['default_formatter'])) {
         $formatter = $field['default_formatter'];
         if (!field_info_formatter_types($formatter)) {
             $context->logWarning(sprintf("%s: field %s defines non existing default formatter: %s", $node->getPath(), $fieldName, $formatter));
             $formatter = null;
         }
     }
     if ($formatter) {
         $default = array('type' => $formatter, 'label' => 'hidden', 'settings' => field_info_formatter_settings($formatter));
     }
     return $default;
 }
Esempio n. 9
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;
}
 /**
  * @Then /^I should have a "([^"]*)" field as a "([^"]*)" type, has a "([^"]*)" widget, (not required|required), and allows (\d+|(?i)unlimited) value[s]?[.]?$/
  */
 public function iShouldHaveAFieldAsTypeHasAWidgetRequiredAndAllowsValue($name, $type, $widget, $required, $cardinality)
 {
     if (strcasecmp($cardinality, 'unlimited') == 0) {
         $cardinality = '-1';
     }
     $fields = field_info_instances("node", $this->contentType->type);
     $wantedField = NULL;
     foreach ($fields as $field) {
         if ($field['label'] == $name) {
             $wantedField = $field;
         }
     }
     assertNotEmpty($wantedField, "Field with the label {$name} doesn't exist");
     $fieldInfo = field_info_field($wantedField['field_name']);
     $widgetInfo = field_info_widget_types();
     $fieldTypeInfo = field_info_field_types();
     $wantedField['widget']['info'] = $widgetInfo[$wantedField['widget']['type']];
     $wantedField['type'] = $fieldTypeInfo[$fieldInfo['type']];
     assertEquals($type, $wantedField['type']['label'], "{$name} doesn't have the type {$type}. Instead it has " . $wantedField['type']['label'] . '.');
     assertEquals($widget, $wantedField['widget']['info']['label'], "{$name} doesn't have the widget type {$widget}. Instead it has " . $wantedField['widget']['info']['label'] . '.');
     $fieldRequired = $wantedField['required'] ? 'required' : 'not required';
     assertEquals($required, $fieldRequired, "{$name} is marked '{$fieldRequired}'. It should be '{$required}'.");
     assertEquals($cardinality, $fieldInfo['cardinality'], "{$name} allows " . $fieldInfo['cardinality'] . " values. It should only allow {$cardinality} values.");
     $this->fieldList[] = $wantedField['field_name'];
 }
 protected function getTargetType($field_name)
 {
     $field_info = \field_info_field($field_name);
     if (!isset($field_info['settings']['target_type'])) {
         throw new EntityReferenceHandlerException('The field ' . $field_name . ' does not have a proper target type.');
     }
     return $field_info['settings']['target_type'];
 }
Esempio n. 12
0
 public function getExistingObject(NodeInterface $node, Context $context)
 {
     /* @var $node FieldNode */
     $name = $node->getName();
     if ($info = field_info_field($name)) {
         return $info;
     }
     $context->logCritical(sprintf("%s: does not exist", $node->getPath()));
 }
Esempio n. 13
0
 /**
  * Implements QuickEditInPlaceEditorInterface::isCompatible().
  *
  * @see Drupal 8's \Drupal\quickedit\Plugin\InPlaceEditor\PlainTextEditor::isCompatible().
  */
 public function isCompatible(array $instance, array $items)
 {
     $field = field_info_field($instance['field_name']);
     // This editor is incompatible with multivalued fields.
     $cardinality_allows = $field['cardinality'] == 1;
     // This editor is incompatible with processed ("rich") text fields.
     $no_text_processing = empty($instance['settings']['text_processing']);
     return $cardinality_allows && $no_text_processing;
 }
Esempio n. 14
0
 public static function installFields(array $fields)
 {
     foreach ($fields as $index => $field) {
         if (field_info_field($field['field_name'])) {
             continue;
         }
         $fields[$index] = field_create_field($field);
     }
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 protected function publicFields()
 {
     $public_fields = parent::publicFields();
     $public_fields['nid'] = array('property' => 'node', 'sub_property' => 'nid');
     // Add a custom field for test only.
     if (field_info_field('comment_text')) {
         $public_fields['comment_text'] = array('property' => 'comment_text', 'sub_property' => 'value');
     }
     return $public_fields;
 }
 /**
  * @param string $field_name
  *   Machine name or label of a field.
  *
  * @return array
  *   Drupal field definition.
  */
 public static function getUserEntityFieldInfo($field_name)
 {
     $locators = self::getUserEntityFields('locators');
     $field = [];
     // Try to find a field by label or machine name.
     if (isset($locators[$field_name])) {
         $field = field_info_field($locators[$field_name]);
     }
     // This check is necessary for always return an array only.
     return empty($field) ? [] : $field;
 }
  /**
   * Overrides RestfulExampleArticlesResource::publicFieldsInfo().
   */
  public function publicFieldsInfo() {
    $public_fields = parent::publicFieldsInfo();

    $public_fields['body'] = array(
      'property' => 'body',
      'sub_property' => 'value',
    );

    $public_fields['tags'] = array(
      'property' => 'field_tags',
      'resource' => array(
        'tags' => 'tags',
      ),
    );

    $public_fields['image'] = array(
      'property' => 'field_image',
      'process_callbacks' => array(
        array($this, 'imageProcess'),
      ),
      'image_styles' => array('thumbnail', 'medium', 'large'),
    );

    // By checking that the field exists, we allow re-using this class on
    // different tests, where different fields exist.
    if (field_info_field('field_images')) {
      $public_fields['images'] = array(
        'property' => 'field_images',
        'process_callbacks' => array(
          array($this, 'imageProcess'),
        ),
        'image_styles' => array('thumbnail', 'medium', 'large'),
      );
    }

    $public_fields['user'] = array(
      'property' => 'author',
      'resource' => array(
        // The bundle of the entity.
        'user' => array(
          // The name of the resource to map to.
          'name' => 'users',
          // Determines if the entire resource should appear, or only the ID.
          'full_view' => TRUE,
        ),
      ),
    );

    $public_fields['static'] = array(
      'callback' => 'static::randomNumber',
    );

    return $public_fields;
  }
 /**
  * Test base field saving.
  *
  * @dataProvider fieldDataProvider
  */
 public function testFieldSaving($field_name, $vocabulary_name)
 {
     $service = multisite_config_service('field');
     $service->createBaseField($field_name, 'taxonomy_term_reference')->setVocabulary($vocabulary_name)->save();
     $field = field_info_field($field_name);
     $this->assertEquals('taxonomy_term_reference', $field['type']);
     $this->assertEquals($field_name, $field['field_name']);
     $this->assertEquals('taxonomy', $field['module']);
     $this->assertEquals(1, $field['cardinality']);
     $this->assertEquals($vocabulary_name, $field['settings']['allowed_values'][0]['vocabulary']);
     field_delete_field($field_name);
 }
/**
 * Callback to return a field collection label.
 *
 * @param array $context
 *   An array with contextual information used to build the title:
 *     - field_as_label the name of the field used as label.
 *     - field_collection_item_wrapper the field collection for which
 *     a label is created.
 *
 * @return string
 *   Title for the field collection.
 */
function field_collection_fieldset_field_as_label_callback($context)
{
    $title = '';
    if ($field_value = $context['field_collection_item_wrapper']->{$context['field_as_label']}->value()) {
        $info = field_info_field($context['field_as_label']);
        switch ($info['field_type']) {
            case 'text':
                $title = is_array($field_value) ? strip_tags($field_value['value']) : strip_tags($field_value);
                break;
        }
    }
    return $title;
}
Esempio n. 20
0
 public static function reference($type, $value, $name)
 {
     if (!self::checkFieldValue($value, 'target_id')) {
         return null;
     }
     $info = field_info_field($name);
     if (!isset($info['settings']['target_type'])) {
         trigger_error('Target type couldnt be found.', E_USER_WARNING);
         return null;
     }
     $target_type = $info['settings']['target_type'];
     return new EntityReferenceFieldValue($type, $value, $target_type);
 }
 /**
  * Validate the semester field.
  */
 function validationSemester($field_name_name, $value)
 {
     // Allow empty value for the semester.
     if (empty($value)) {
         return;
     }
     $info = field_info_field($field_name_name);
     // Validate the semester.
     $allowed_values = $info['settings']['allowed_values'] + array('N/A' => 'N/A');
     if (!in_array($value, $allowed_values)) {
         $params = array('@allowed-values' => implode(', ', $allowed_values), '@value' => $value);
         $this->setError($field_name_name, 'The given value (@value) is not a valid value for semester, and it should be one of the followings (@allowed-values)', $params);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function preprocess($value)
 {
     $field_info = field_info_field($this->getProperty());
     if ($field_info['cardinality'] == 1) {
         // Single value.
         return array('fid' => $value, 'display' => TRUE);
     }
     $value = is_array($value) ? $value : explode(',', $value);
     $return = array();
     foreach ($value as $delta => $single_value) {
         $return[$delta] = array('fid' => $single_value, 'display' => TRUE);
     }
     return $return;
 }
Esempio n. 23
0
 /**
  * Load a field's configuration and instance configuration by an
  * entity_type.bundle.field_name identifier.
  */
 protected function field_load($identifier)
 {
     list($entity_type, $field_name, $bundle) = explode('.', $identifier);
     $field_info = field_info_field($field_name);
     $instance_info = field_info_instance($entity_type, $field_name, $bundle);
     if ($field_info && $instance_info) {
         unset($field_info['id']);
         unset($field_info['bundles']);
         unset($instance_info['id']);
         unset($instance_info['field_id']);
         return array('field_config' => $field_info, 'field_instance' => $instance_info);
     }
     return FALSE;
 }
 /**
  * Overrides ResourceNode::publicFields().
  */
 protected function publicFields()
 {
     $public_fields = parent::publicFields();
     $public_fields['body'] = array('property' => 'body', 'sub_property' => 'value');
     $public_fields['tags'] = array('property' => 'field_tags', 'resource' => array('name' => 'tags', 'majorVersion' => 1, 'minorVersion' => 0));
     $public_fields['image'] = array('property' => 'field_image', 'process_callbacks' => array(array($this, 'imageProcess')), 'image_styles' => array('thumbnail', 'medium', 'large'));
     // By checking that the field exists, we allow re-using this class on
     // different tests, where different fields exist.
     if (field_info_field('field_images')) {
         $public_fields['images'] = array('property' => 'field_images', 'process_callbacks' => array(array($this, 'imageProcess')), 'image_styles' => array('thumbnail', 'medium', 'large'));
     }
     $public_fields['user'] = array('property' => 'author', 'resource' => array('name' => 'users', 'fullView' => TRUE, 'majorVersion' => 1, 'minorVersion' => 0));
     $public_fields['static'] = array('callback' => '\\Drupal\\restful_example\\Plugin\\resource\\node\\article\\v1\\Articles__1_5::randomNumber');
     return $public_fields;
 }
 /**
  * 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;
 }
Esempio n. 26
0
 /**
  * Implements QuickEditInPlaceEditorInterface::getMetadata().
  *
  * @see Drupal 8's \Drupal\editor\Plugin\quickedit\editor\Editor::getMetadata().
  */
 public function getMetadata(array $instance, array $items)
 {
     $format_id = $items[0]['format'];
     $metadata['format'] = $format_id;
     $metadata['formatHasTransformations'] = (bool) count(array_intersect(array(FILTER_TYPE_TRANSFORM_REVERSIBLE, FILTER_TYPE_TRANSFORM_IRREVERSIBLE), filter_get_filter_types_by_format($format_id)));
     // This part does not exist in the equivalent Drupal 8 code, because in Drupal
     // 8 we leverage the new Text Editor module, which takes care of all of this
     // for us. We could send this information in the attachments callback (like in
     // Drupal 8), but this makes the metadata for each field nicely contained,
     // which is simpler.
     // @todo Consider moving this to the attachments callback.
     module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
     if ($settings = ckeditor_profiles_compile($format_id)) {
         // Clean up a few settings.
         foreach (array('customConfig', 'show_toggle', 'ss', 'contentsCss', 'stylesCombo_stylesSet') as $config_item) {
             unset($settings[$config_item]);
         }
         // CKEditor.module stores the toolbar configuration as a non-standard JSON
         // serialization. In case they one day fix that, we check if it is indeed
         // still serialized.
         // See http://drupal.org/node/1906490.
         if (is_string($settings['toolbar'])) {
             // This bizarre code comes from ckeditor_admin_profile_form_validate().
             $toolbar = $settings['toolbar'];
             $toolbar = str_replace("'", '"', $toolbar);
             $toolbar = preg_replace('/(\\w*)\\s*\\:/', '"${1}":', $toolbar);
             $settings['toolbar'] = json_decode($toolbar);
         }
         // For some reasons when ckeditor is in profiles/libraries ckeditor module
         // defaults to the kama skin that doesn't exists in CKEditor 4 standard.
         // @todo remove? might be too brutal.
         if ($settings['skin'] == 'kama') {
             $settings['skin'] = 'moono';
         }
         //[#1473010]
         // @todo see if this is needed.
         $field = field_info_field($instance['field_name']);
         if (isset($settings['scayt_sLang'])) {
             $settings['scayt_language'] = $settings['scayt_sLang'];
             unset($settings['scayt_sLang']);
         } elseif (!empty($field["#language"]) && $field["#language"] != LANGUAGE_NONE) {
             $settings['scayt_language'] = ckeditor_scayt_langcode($field["#language"]);
         }
         // Set the collected metadata.
         $metadata['ckeditorSettings'] = $settings;
     }
     return $metadata;
 }
 /**
  * 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;
 }
Esempio n. 28
0
 /**
  * Implements QuickEditInPlaceEditorInterface::isCompatible().
  *
  * @see Drupal 8's \Drupal\editor\Plugin\quickedit\editor\Editor::isCompatible().
  */
 public function isCompatible(array $instance, array $items)
 {
     $field = field_info_field($instance['field_name']);
     // This editor is incompatible with multivalued fields.
     if ($field['cardinality'] != 1) {
         return FALSE;
     } elseif (!empty($instance['settings']['text_processing'])) {
         $format_id = $items[0]['format'];
         if ($format = filter_format_load($format_id)) {
             editor_format_ensure_additional_properties($format);
             if ($format->editor == 'ckeditor') {
                 return TRUE;
             }
         }
         return FALSE;
     }
 }
 /**
  * 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;
 }
 /**
  * Find all the users that are allowed to be assigned to the issue.
  *
  * @return array
  *   An array of users that can be assigned to the issue this selector is
  *   attached to. The array contains and is indexed by user ID (uid). If
  *   there are no allowed users or we hit some other error, the array will
  *   be empty.
  */
 protected function getAllowedAssignees()
 {
     $return = array();
     if ($this->entity) {
         $settings = $this->field['settings'];
         $project_field = field_info_field($settings['handler_settings']['project_field']);
         $project_field_items = field_get_items($this->entity_type, $this->entity, $project_field['field_name']);
         $referenced_project_id = $project_field_items[0]['target_id'];
         if ($referenced_project_id) {
             $projects = entity_load('node', array($referenced_project_id));
             $this->project = $projects[$referenced_project_id];
         }
         $project_field_items = field_get_items($this->entity_type, $this->entity, $this->field['field_name']);
         $current = $project_field_items[0]['target_id'];
         $return = project_issue_assigned_choices($this->entity, $this->project, $current);
     }
     return $return;
 }