本文整理汇总了PHP中entity_get_bundles函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_get_bundles函数的具体用法?PHP entity_get_bundles怎么用?PHP entity_get_bundles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_get_bundles函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructs a new FieldStorageConfigListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The 'field type' plugin manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager)
{
parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id()));
$this->entityManager = $entity_manager;
$this->bundles = entity_get_bundles();
$this->fieldTypeManager = $field_type_manager;
$this->fieldTypes = $this->fieldTypeManager->getDefinitions();
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:18,代码来源:FieldStorageConfigListBuilder.php
示例2: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$bundles = entity_get_bundles();
$bundle_label = $bundles[$this->fieldGroup->entity_type][$this->fieldGroup->bundle]['label'];
field_group_group_delete($this->fieldGroup);
drupal_set_message(t('The group %group has been deleted from the %type content type.', array('%group' => t($this->fieldGroup->label), '%type' => $bundle_label)));
// Redirect.
$form_state->setRedirectUrl($this->getCancelUrl());
}
开发者ID:penguinclub,项目名称:penguinweb_drupal8,代码行数:12,代码来源:FieldGroupDeleteForm.php
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$bundles = entity_get_bundles($this->entity->id());
if (!empty($bundles) && empty($bundles[$this->entity->id()])) {
$warning_message = '<p>' . $this->formatPlural(count($bundles), '%type has 1 bundle. Please delete all %type bundles.', '%type has @count bundles. Please delete all %type bundles.', array('%type' => $this->entity->label())) . '</p>';
$form['description'] = array('#markup' => $warning_message);
$form['title'] = $this->getQuestion();
return $form;
}
return parent::buildForm($form, $form_state);
}
开发者ID:jokas,项目名称:d8.dev,代码行数:14,代码来源:EckEntityTypeDeleteForm.php
示例4: getValueOptions
/**
* Overrides \Drupal\views\Plugin\views\filter\InOperator::getValueOptions().
*/
public function getValueOptions()
{
if (!isset($this->value_options)) {
$types = entity_get_bundles($this->entityTypeId);
$this->value_title = t('@entity types', array('@entity' => $this->entityType->getLabel()));
$options = array();
foreach ($types as $type => $info) {
$options[$type] = $info['label'];
}
asort($options);
$this->value_options = $options;
}
return $this->value_options;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:17,代码来源:Bundle.php
示例5: setUp
protected function setUp()
{
parent::setUp();
$this->drupalCreateContentType(array('type' => 'test_bundle'));
$this->drupalCreateContentType(array('type' => 'test_bundle_2'));
$this->entityBundles = entity_get_bundles('node');
$this->entities['count'] = 0;
foreach ($this->entityBundles as $key => $info) {
for ($i = 0; $i < 5; $i++) {
$entity = entity_create('node', array('label' => $this->randomMachineName(), 'uid' => 1, 'type' => $key));
$entity->save();
$this->entities[$key][$entity->id()] = $entity;
$this->entities['count']++;
}
}
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:16,代码来源:FilterEntityBundleTest.php
示例6: getDerivativeDefinitions
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition)
{
// Also keep the 'entity' defined as is.
$this->derivatives[''] = $base_plugin_definition;
// Add definitions for each entity type and bundle.
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id] = array('label' => $entity_type->getLabel(), 'constraints' => $entity_type->getConstraints()) + $base_plugin_definition;
// Incorporate the bundles as entity:$entity_type:$bundle, if any.
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
if ($bundle !== $entity_type_id) {
$this->derivatives[$entity_type_id . ':' . $bundle] = array('label' => $bundle_info['label'], 'constraints' => $this->derivatives[$entity_type_id]['constraints']) + $base_plugin_definition;
}
}
}
return $this->derivatives;
}
开发者ID:318io,项目名称:318-io,代码行数:19,代码来源:EntityDeriver.php
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, FieldConfigInterface $field_config = NULL)
{
$this->field = $field_config;
$form_state->set('field', $field_config);
$bundle = $this->field->bundle;
$entity_type = $this->field->entity_type;
$field_storage = $this->field->getFieldStorageDefinition();
$bundles = entity_get_bundles();
$form_title = $this->t('%field settings for %bundle', array('%field' => $this->field->getLabel(), '%bundle' => $bundles[$entity_type][$bundle]['label']));
$form['#title'] = $form_title;
$form['#field'] = $field_storage;
// Create an arbitrary entity object (used by the 'default value' widget).
$ids = (object) array('entity_type' => $this->field->entity_type, 'bundle' => $this->field->bundle, 'entity_id' => NULL);
$form['#entity'] = _field_create_entity_from_ids($ids);
$items = $form['#entity']->get($this->field->getName());
$item = $items->first() ?: $items->appendItem();
if (!empty($field_storage->locked)) {
$form['locked'] = array('#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->field->getLabel())));
return $form;
}
// Create a form structure for the field values.
$form['field'] = array('#tree' => TRUE);
// Build the non-configurable field values.
$form['field']['field_name'] = array('#type' => 'value', '#value' => $this->field->getName());
$form['field']['entity_type'] = array('#type' => 'value', '#value' => $entity_type);
$form['field']['bundle'] = array('#type' => 'value', '#value' => $bundle);
// Build the configurable field values.
$form['field']['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => $this->field->getLabel() ?: $field_storage->getName(), '#required' => TRUE, '#weight' => -20);
$form['field']['description'] = array('#type' => 'textarea', '#title' => $this->t('Help text'), '#default_value' => $this->field->getDescription(), '#rows' => 5, '#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => $this->displayAllowedTags())) . '<br />' . $this->t('This field supports tokens.'), '#weight' => -10);
$form['field']['required'] = array('#type' => 'checkbox', '#title' => $this->t('Required field'), '#default_value' => $this->field->isRequired(), '#weight' => -5);
// Add field settings for the field type and a container for third party
// settings that modules can add to via hook_form_FORM_ID_alter().
$form['field']['settings'] = $item->fieldSettingsForm($form, $form_state);
$form['field']['settings']['#weight'] = 10;
$form['field']['third_party_settings'] = array();
$form['field']['third_party_settings']['#weight'] = 11;
// Add handling for default value.
if ($element = $items->defaultValuesForm($form, $form_state)) {
$element = array_merge($element, array('#type' => 'details', '#title' => $this->t('Default value'), '#open' => TRUE, '#description' => $this->t('The default value for this field, used when creating new content.')));
$form['field']['default_value'] = $element;
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save settings'), '#button_type' => 'primary');
$form['actions']['delete'] = array('#type' => 'submit', '#value' => $this->t('Delete field'), '#submit' => array('::delete'));
return $form;
}
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:49,代码来源:FieldEditForm.php
示例8: setUp
protected function setUp()
{
parent::setUp(FALSE);
$this->drupalCreateContentType(array('type' => 'test_bundle'));
$this->drupalCreateContentType(array('type' => 'test_bundle_2'));
ViewTestData::createTestViews(get_class($this), array('views_test_config'));
$this->entityBundles = entity_get_bundles('node');
$this->entities['count'] = 0;
foreach ($this->entityBundles as $key => $info) {
for ($i = 0; $i < 5; $i++) {
$entity = Node::create(['title' => $this->randomString(), 'uid' => 1, 'type' => $key]);
$entity->save();
$this->entities[$key][$entity->id()] = $entity;
$this->entities['count']++;
}
}
}
开发者ID:318io,项目名称:318-io,代码行数:17,代码来源:FilterEntityBundleTest.php
示例9: buildLegend
/**
* @param \Drupal\field\Plugin\Core\Entity\Field[] $fields
*
* @return array
*/
protected function buildLegend(array $fields)
{
$types = array();
foreach ($fields as $field_name => $field) {
foreach ($field['bundles'] as $entity_type => $bundles) {
$bundle_info = entity_get_bundles($entity_type);
foreach ($bundles as $bundle) {
if (!isset($types[$bundle])) {
$types[$bundle]['entity_type'] = $entity_type;
$types[$bundle]['field_name'] = $field_name;
$types[$bundle]['bundle'] = $bundle;
$types[$bundle]['label'] = $bundle_info[$bundle]['label'];
}
}
}
}
return $types;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:23,代码来源:Bundle.php
示例10: getReferenceableEntities
/**
* {@inheritdoc}
*/
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0)
{
if ($match || $limit) {
return parent::getReferenceableEntities($match, $match_operator, $limit);
}
$options = array();
$bundles = entity_get_bundles('taxonomy_term');
$bundle_names = !empty($this->instance['settings']['handler_settings']['target_bundles']) ? $this->instance['settings']['handler_settings']['target_bundles'] : array_keys($bundles);
foreach ($bundle_names as $bundle) {
if ($vocabulary = entity_load('taxonomy_vocabulary', $bundle)) {
if ($terms = taxonomy_get_tree($vocabulary->id(), 0, NULL, TRUE)) {
foreach ($terms as $term) {
$options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . String::checkPlain($term->getName());
}
}
}
}
return $options;
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:22,代码来源:TermSelection.php
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$field_storage = $this->entity->getFieldStorageDefinition();
$bundles = entity_get_bundles();
$bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label'];
if ($field_storage && !$field_storage->locked) {
$this->entity->delete();
drupal_set_message($this->t('The field %field has been deleted from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)));
} else {
drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)), 'error');
}
$form_state->setRedirectUrl($this->getCancelUrl());
// Fields are purged on cron. However field module prevents disabling modules
// when field types they provided are used in a field until it is fully
// purged. In the case that a field has minimal or no content, a single call
// to field_purge_batch() will remove it from the system. Call this with a
// low batch limit to avoid administrators having to wait for cron runs when
// removing fields that meet this criteria.
field_purge_batch(10);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:23,代码来源:FieldConfigDeleteForm.php
示例12: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, FieldInstanceConfigInterface $field_instance_config = NULL)
{
$this->instance = $form_state['instance'] = $field_instance_config;
$bundle = $this->instance->bundle;
$entity_type = $this->instance->entity_type;
$field_storage = $this->instance->getFieldStorageDefinition();
$bundles = entity_get_bundles();
$form_title = $this->t('%instance settings for %bundle', array('%instance' => $this->instance->getLabel(), '%bundle' => $bundles[$entity_type][$bundle]['label']));
$form['#title'] = $form_title;
$form['#field'] = $field_storage;
// Create an arbitrary entity object (used by the 'default value' widget).
$ids = (object) array('entity_type' => $this->instance->entity_type, 'bundle' => $this->instance->bundle, 'entity_id' => NULL);
$form['#entity'] = _field_create_entity_from_ids($ids);
$items = $form['#entity']->get($this->instance->getName());
if (!empty($field_storage->locked)) {
$form['locked'] = array('#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->instance->getLabel())));
return $form;
}
// Create a form structure for the instance values.
$form['instance'] = array('#tree' => TRUE);
// Build the non-configurable instance values.
$form['instance']['field_name'] = array('#type' => 'value', '#value' => $this->instance->getName());
$form['instance']['entity_type'] = array('#type' => 'value', '#value' => $entity_type);
$form['instance']['bundle'] = array('#type' => 'value', '#value' => $bundle);
// Build the configurable instance values.
$form['instance']['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => $this->instance->getLabel() ?: $field_storage->getName(), '#required' => TRUE, '#weight' => -20);
$form['instance']['description'] = array('#type' => 'textarea', '#title' => $this->t('Help text'), '#default_value' => $this->instance->getDescription(), '#rows' => 5, '#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '<br />' . $this->t('This field supports tokens.'), '#weight' => -10);
$form['instance']['required'] = array('#type' => 'checkbox', '#title' => $this->t('Required field'), '#default_value' => $this->instance->isRequired(), '#weight' => -5);
// Add instance settings for the field type.
$form['instance']['settings'] = $items[0]->instanceSettingsForm($form, $form_state);
$form['instance']['settings']['#weight'] = 10;
// Add handling for default value.
if ($element = $items->defaultValuesForm($form, $form_state)) {
$element += array('#type' => 'details', '#title' => $this->t('Default value'), '#open' => TRUE, '#description' => $this->t('The default value for this field, used when creating new content.'));
$form['instance']['default_value'] = $element;
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save settings'));
$form['actions']['delete'] = array('#type' => 'submit', '#value' => $this->t('Delete field'), '#submit' => array(array($this, 'delete')));
return $form;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:44,代码来源:FieldInstanceEditForm.php
示例13: testFieldAdminHandler
/**
* Tests the Entity Reference Admin UI.
*/
public function testFieldAdminHandler()
{
$bundle_path = 'admin/structure/types/manage/' . $this->type;
// First step: 'Add new field' on the 'Manage fields' page.
$this->drupalPostForm($bundle_path . '/fields', array('fields[_add_new_field][label]' => 'Test label', 'fields[_add_new_field][field_name]' => 'test', 'fields[_add_new_field][type]' => 'entity_reference'), t('Save'));
// Node should be selected by default.
$this->assertFieldByName('field[settings][target_type]', 'node');
// Check that all entity types can be referenced.
$this->assertFieldSelectOptions('field[settings][target_type]', array_keys(\Drupal::entityManager()->getDefinitions()));
// Second step: 'Instance settings' form.
$this->drupalPostForm(NULL, array(), t('Save field settings'));
// The base handler should be selected by default.
$this->assertFieldByName('instance[settings][handler]', 'default');
// The base handler settings should be displayed.
$entity_type_id = 'node';
$bundles = entity_get_bundles($entity_type_id);
foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertFieldByName('instance[settings][handler_settings][target_bundles][' . $bundle_name . ']');
}
reset($bundles);
// Test the sort settings.
// Option 0: no sort.
$this->assertFieldByName('instance[settings][handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('instance[settings][handler_settings][sort][direction]');
// Option 1: sort by field.
$this->drupalPostAjaxForm(NULL, array('instance[settings][handler_settings][sort][field]' => 'nid'), 'instance[settings][handler_settings][sort][field]');
$this->assertFieldByName('instance[settings][handler_settings][sort][direction]', 'ASC');
// Test that a non-translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='instance[settings][handler_settings][sort][field]']/option[@value='nid']");
// Test that a translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='instance[settings][handler_settings][sort][field]']/option[@value='title']");
// Test that a configurable field is a sort option.
$this->assertFieldByXPath("//select[@name='instance[settings][handler_settings][sort][field]']/option[@value='body.value']");
// Set back to no sort.
$this->drupalPostAjaxForm(NULL, array('instance[settings][handler_settings][sort][field]' => '_none'), 'instance[settings][handler_settings][sort][field]');
$this->assertNoFieldByName('instance[settings][handler_settings][sort][direction]');
// Third step: confirm.
$this->drupalPostForm(NULL, array('instance[settings][handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles)), t('Save settings'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="field-test"]/td[1]', 'Test label', 'Field was created and appears in the overview page.');
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:44,代码来源:EntityReferenceAdminTest.php
示例14: writeCache
/**
* Writes the cache of type links.
*/
protected function writeCache()
{
$data = array();
// Type URIs correspond to bundles. Iterate through the bundles to get the
// URI and data for them.
$entity_types = \Drupal::entityManager()->getDefinitions();
foreach (entity_get_bundles() as $entity_type_id => $bundles) {
// Only content entities are supported currently.
// @todo Consider supporting config entities.
if ($entity_types[$entity_type_id]->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
continue;
}
foreach ($bundles as $bundle => $bundle_info) {
// Get a type URI for the bundle.
$bundle_uri = $this->getTypeUri($entity_type_id, $bundle);
$data[$bundle_uri] = array('entity_type' => $entity_type_id, 'bundle' => $bundle);
}
}
// These URIs only change when entity info changes, so cache it permanently
// and only clear it when entity_info is cleared.
$this->cache->set('rest:links:types', $data, Cache::PERMANENT, array('entity_types'));
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:25,代码来源:TypeLinkManager.php
示例15: elementValidate
/**
* {@inheritdoc}
*/
public function elementValidate($element, &$form_state, $form)
{
$value = array();
// If a value was entered into the autocomplete.
$handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
$bundles = entity_get_bundles($this->getFieldSetting('target_type'));
$auto_create = $this->getSelectionHandlerSetting('auto_create');
if (!empty($element['#value'])) {
$value = array();
foreach (Tags::explode($element['#value']) as $input) {
$match = FALSE;
// Take "label (entity id)', match the ID from parenthesis when it's a
// number.
if (preg_match("/.+\\((\\d+)\\)/", $input, $matches)) {
$match = $matches[1];
} elseif (preg_match("/.+\\(([\\w.]+)\\)/", $input, $matches)) {
$match = $matches[1];
} else {
// Try to get a match from the input string when the user didn't use
// the autocomplete but filled in a value manually.
$match = $handler->validateAutocompleteInput($input, $element, $form_state, $form, !$auto_create);
}
if ($match) {
$value[] = array('target_id' => $match);
} elseif ($auto_create && (count($this->getSelectionHandlerSetting('target_bundles')) == 1 || count($bundles) == 1)) {
// Auto-create item. See
// \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
$value[] = array('target_id' => NULL, 'entity' => $this->createNewEntity($input, $element['#autocreate_uid']));
}
}
}
// Change the element['#parents'], so in form_set_value() we
// populate the correct key.
array_pop($element['#parents']);
form_set_value($element, $value, $form_state);
}
开发者ID:alnutile,项目名称:drunatra,代码行数:39,代码来源:AutocompleteTagsWidget.php
示例16: bundleOptions
/**
* Provides a list of bundle options for use in select lists.
*
* @return array
* A keyed array of bundle => label.
*/
protected function bundleOptions()
{
$options = array();
foreach (entity_get_bundles($this->entityType()) as $bundle => $info) {
if (!empty($info['label'])) {
$options[$bundle] = $info['label'];
} else {
$options[$bundle] = $bundle;
}
}
return $options;
}
开发者ID:alnutile,项目名称:drunatra,代码行数:18,代码来源:EntityProcessor.php
示例17: fieldInfoPage
public function fieldInfoPage()
{
$field_info = Field::fieldInfo();
$info = $field_info->getFields();
$output = kprint_r($info, TRUE, t('Fields'));
$info = $field_info->getInstances();
$output .= kprint_r($info, TRUE, t('Instances'));
$info = entity_get_bundles();
$output .= kprint_r($info, TRUE, t('Bundles'));
$info = \Drupal::service('plugin.manager.field.field_type')->getConfigurableDefinitions();
$output .= kprint_r($info, TRUE, t('Field types'));
$info = \Drupal::service('plugin.manager.field.formatter')->getDefinitions();
$output .= kprint_r($info, TRUE, t('Formatter types'));
//$info = field_info_storage_types();
//$output .= kprint_r($info, TRUE, t('Storage types'));
$info = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
$output .= kprint_r($info, TRUE, t('Widget types'));
return $output;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:DevelController.php
示例18: buildFilters
/**
* Builds the form structure for selecting the view's filters.
*
* By default, this adds "of type" and "tagged with" filters (when they are
* available).
*/
protected function buildFilters(&$form, FormStateInterface $form_state)
{
module_load_include('inc', 'views_ui', 'admin');
$bundles = entity_get_bundles($this->entityTypeId);
// If the current base table support bundles and has more than one (like user).
if (!empty($bundles) && $this->entityType && $this->entityType->hasKey('bundle')) {
// Get all bundles and their human readable names.
$options = array('all' => $this->t('All'));
foreach ($bundles as $type => $bundle) {
$options[$type] = $bundle['label'];
}
$form['displays']['show']['type'] = array('#type' => 'select', '#title' => $this->t('of type'), '#options' => $options);
$selected_bundle = static::getSelected($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'));
}
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:WizardPluginBase.php
示例19: testFieldAdminHandler
/**
* Tests the Entity Reference Admin UI.
*/
public function testFieldAdminHandler()
{
$bundle_path = 'admin/structure/types/manage/' . $this->type;
// First step: 'Add new field' on the 'Manage fields' page.
$this->drupalGet($bundle_path . '/fields/add-field');
// Check if the commonly referenced entity types appear in the list.
$this->assertOption('edit-new-storage-type', 'field_ui:entity_reference:node');
$this->assertOption('edit-new-storage-type', 'field_ui:entity_reference:user');
$this->drupalPostForm(NULL, array('label' => 'Test label', 'field_name' => 'test', 'new_storage_type' => 'entity_reference'), t('Save and continue'));
// Node should be selected by default.
$this->assertFieldByName('settings[target_type]', 'node');
// Check that all entity types can be referenced.
$this->assertFieldSelectOptions('settings[target_type]', array_keys(\Drupal::entityManager()->getDefinitions()));
// Second step: 'Field settings' form.
$this->drupalPostForm(NULL, array(), t('Save field settings'));
// The base handler should be selected by default.
$this->assertFieldByName('settings[handler]', 'default:node');
// The base handler settings should be displayed.
$entity_type_id = 'node';
$bundles = entity_get_bundles($entity_type_id);
foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertFieldByName('settings[handler_settings][target_bundles][' . $bundle_name . ']');
}
reset($bundles);
// Test the sort settings.
// Option 0: no sort.
$this->assertFieldByName('settings[handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('settings[handler_settings][sort][direction]');
// Option 1: sort by field.
$this->drupalPostAjaxForm(NULL, array('settings[handler_settings][sort][field]' => 'nid'), 'settings[handler_settings][sort][field]');
$this->assertFieldByName('settings[handler_settings][sort][direction]', 'ASC');
// Test that a non-translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='nid']");
// Test that a translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='title']");
// Test that a configurable field is a sort option.
$this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='body.value']");
// Set back to no sort.
$this->drupalPostAjaxForm(NULL, array('settings[handler_settings][sort][field]' => '_none'), 'settings[handler_settings][sort][field]');
$this->assertNoFieldByName('settings[handler_settings][sort][direction]');
// Third step: confirm.
$this->drupalPostForm(NULL, array('required' => '1', 'settings[handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles)), t('Save settings'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="field-test"]/td[1]', 'Test label', 'Field was created and appears in the overview page.');
// Check that the field settings form can be submitted again, even when the
// field is required.
// The first 'Edit' link is for the Body field.
$this->clickLink(t('Edit'), 1);
$this->drupalPostForm(NULL, array(), t('Save settings'));
// Switch the target type to 'taxonomy_term' and check that the settings
// specific to its selection handler are displayed.
$field_name = 'node.' . $this->type . '.field_test';
$edit = array('settings[target_type]' => 'taxonomy_term');
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->assertFieldByName('settings[handler_settings][auto_create]');
// Switch the target type to 'user' and check that the settings specific to
// its selection handler are displayed.
$field_name = 'node.' . $this->type . '.field_test';
$edit = array('settings[target_type]' => 'user');
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->assertFieldByName('settings[handler_settings][filter][type]', '_none');
// Switch the target type to 'node'.
$field_name = 'node.' . $this->type . '.field_test';
$edit = array('settings[target_type]' => 'node');
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
// Try to select the views handler.
$edit = array('settings[handler]' => 'views');
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$this->assertRaw(t('No eligible views were found. <a href=":create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href=":existing">existing view</a>.', array(':create' => \Drupal::url('views_ui.add'), ':existing' => \Drupal::url('entity.view.collection'))));
$this->drupalPostForm(NULL, $edit, t('Save settings'));
// If no eligible view is available we should see a message.
$this->assertText('The views entity selection mode requires a view.');
// Enable the entity_reference_test module which creates an eligible view.
$this->container->get('module_installer')->install(array('entity_reference_test'));
$this->resetAll();
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$edit = array('settings[handler_settings][view][view_and_display]' => 'test_entity_reference:entity_reference_1');
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertResponse(200);
// Switch the target type to 'entity_test'.
$edit = array('settings[target_type]' => 'entity_test');
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$edit = array('settings[handler]' => 'views');
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$edit = array('required' => FALSE, 'settings[handler_settings][view][view_and_display]' => 'test_entity_reference_entity_test:entity_reference_1');
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertResponse(200);
// Create a new view and display it as a entity reference.
$edit = array('id' => 'node_test_view', 'label' => 'Node Test View', 'show[wizard_key]' => 'node', 'page[create]' => 1, 'page[title]' => 'Test Node View', 'page[path]' => 'test/node/view', 'page[style][style_plugin]' => 'default', 'page[style][row_plugin]' => 'fields');
$this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit'));
$this->drupalPostForm(NULL, array(), t('Duplicate as Entity Reference'));
$this->clickLink(t('Settings'));
$edit = array('style_options[search_fields][title]' => 'title');
//.........这里部分代码省略.........
开发者ID:dmyerson,项目名称:d8ecs,代码行数:101,代码来源:EntityReferenceAdminTest.php
示例20: getAutocreateBundle
/**
* Returns the name of the bundle which will be used for autocreated entities.
*
* @return string
* The bundle name.
*/
protected function getAutocreateBundle()
{
$bundle = NULL;
if ($this->getSelectionHandlerSetting('auto_create')) {
// If the 'target_bundles' setting is restricted to a single choice, we
// can use that.
if (($target_bundles = $this->getSelectionHandlerSetting('target_bundles')) && count($target_bundles) == 1) {
$bundle = reset($target_bundles);
} else {
// @todo Expose a proper UI for choosing the bundle for autocreated
// entities in https://www.drupal.org/node/2412569.
$bundles = entity_get_bundles($this->getFieldSetting('target_type'));
$bundle = key($bundles);
}
}
return $bundle;
}
开发者ID:nsp15,项目名称:Drupal8,代码行数:23,代码来源:EntityReferenceAutocompleteWidget.php
注:本文中的entity_get_bundles函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论