本文整理汇总了PHP中field_info_instances函数的典型用法代码示例。如果您正苦于以下问题:PHP field_info_instances函数的具体用法?PHP field_info_instances怎么用?PHP field_info_instances使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了field_info_instances函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootstrap_clean_blog_form_system_theme_settings_alter
/**
* 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: alterDependencies
/**
* 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: dxray_get_node_type
/**
* Получаем список 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;
}
示例4: settingsForm
/**
* 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;
}
开发者ID:leloulight,项目名称:drupal-micah-blog,代码行数:30,代码来源:EntityReference_SelectionHandler_Generic.class.php
示例5: getInstances
/**
* 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;
}
示例6: getDependencies
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;
}
示例7: getUserEntityFields
/**
* @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];
}
示例8: settingsForm
/**
* 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;
}
示例9: __construct
/**
* @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;
}
}
示例10: settingsForm
/**
* 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;
}
开发者ID:jhwestover,项目名称:opendata-portal,代码行数:49,代码来源:EntityReference_SelectionHandler_Generic.class.php
示例11: settingsForm
/**
* 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;
}
开发者ID:redponey,项目名称:openatrium-7.x-2.51,代码行数:49,代码来源:EntityReference_SelectionHandler_Generic.class.php
示例12: getFieldHandlers
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;
}
示例13: settingsForm
/**
* 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;
}
开发者ID:CuBoulder,项目名称:cu-express-drops-7,代码行数:44,代码来源:EntityReference_SelectionHandler_Generic.class.php
示例14: settingsForm
/**
* 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;
}
示例15: workflow_transition_extra_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;
}