当前位置: 首页>>代码示例>>PHP>>正文


PHP entity_get_bundles函数代码示例

本文整理汇总了PHP中entity_get_bundles函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_get_bundles函数的具体用法?PHP entity_get_bundles怎么用?PHP entity_get_bundles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了entity_get_bundles函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的entity_get_bundles函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。