本文整理汇总了PHP中Drupal\field\Entity\FieldConfig::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldConfig::loadMultiple方法的具体用法?PHP FieldConfig::loadMultiple怎么用?PHP FieldConfig::loadMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\field\Entity\FieldConfig
的用法示例。
在下文中一共展示了FieldConfig::loadMultiple方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$fields = ['' => $this->t('- None -')];
$result = \Drupal::entityQuery('field_config')->condition('field_type', 'uc_price')->execute();
foreach (FieldConfig::loadMultiple($result) as $field) {
$fields[$field->getName()] = $field->label();
}
$form['base_rate'] = array('#type' => 'uc_price', '#title' => $this->t('Base price'), '#description' => $this->t('The starting price for shipping costs.'), '#default_value' => $this->configuration['base_rate'], '#required' => TRUE);
$form['product_rate'] = array('#type' => 'uc_price', '#title' => $this->t('Default product shipping rate'), '#description' => $this->t('Additional shipping cost per product in cart.'), '#default_value' => $this->configuration['product_rate'], '#required' => TRUE);
$form['field'] = array('#type' => 'select', '#title' => $this->t('Product shipping rate override field'), '#description' => $this->t('Overrides the default shipping rate per product for this flat rate shipping method, when the field is attached to a product content type and has a value.'), '#options' => $fields, '#default_value' => $this->configuration['field']);
return $form;
}
示例2: field_post_update_entity_reference_handler_setting
/**
* Fixes the 'handler' setting for entity reference fields.
*/
function field_post_update_entity_reference_handler_setting()
{
foreach (FieldConfig::loadMultiple() as $field_config) {
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$item_class = 'Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\EntityReferenceItem';
$class = $field_type_manager->getPluginClass($field_config->getType());
if ($class === $item_class || is_subclass_of($class, $item_class)) {
// field_field_config_presave() will fix the 'handler' setting on save.
$field_config->save();
}
}
return t('Selection handler for entity reference fields have been adjusted.');
}
示例3: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$fields = ['' => $this->t('- None -')];
$result = \Drupal::entityQuery('field_config')->condition('field_type', 'uc_price')->execute();
foreach (FieldConfig::loadMultiple($result) as $field) {
$fields[$field->getName()] = $field->label();
}
$unit = \Drupal::config('uc_store.settings')->get('weight.units');
$form['base_rate'] = array('#type' => 'uc_price', '#title' => $this->t('Base price'), '#description' => $this->t('The starting price for weight-based shipping costs.'), '#default_value' => $this->configuration['base_rate'], '#required' => TRUE);
$form['product_rate'] = array('#type' => 'uc_price', '#title' => $this->t('Default cost adjustment per @unit', ['@unit' => $unit]), '#description' => $this->t('The amount per weight unit to add to the shipping cost for an item.'), '#default_value' => $this->configuration['product_rate'], '#field_suffix' => $this->t('per @unit', ['@unit' => $unit]), '#required' => TRUE);
$form['field'] = array('#type' => 'select', '#title' => $this->t('Product shipping rate override field'), '#description' => $this->t('Overrides the default shipping rate per @unit for this shipping method, when the field is attached to a product content type and has a value.', ['@unit' => $unit]), '#options' => $fields, '#default_value' => $this->configuration['field']);
return $form;
}
示例4: fieldInfoPage
/**
* Builds the fields info overview page.
*
* @return array
* Array of page elements to render.
*/
public function fieldInfoPage()
{
$fields = FieldStorageConfig::loadMultiple();
ksort($fields);
$output['fields'] = array('#markup' => kprint_r($fields, TRUE, $this->t('Fields')));
$field_instances = FieldConfig::loadMultiple();
ksort($field_instances);
$output['instances'] = array('#markup' => kprint_r($field_instances, TRUE, $this->t('Instances')));
$bundles = $this->entityManager()->getAllBundleInfo();
ksort($bundles);
$output['bundles'] = array('#markup' => kprint_r($bundles, TRUE, $this->t('Bundles')));
$field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions();
ksort($field_types);
$output['field_types'] = array('#markup' => kprint_r($field_types, TRUE, $this->t('Field types')));
$formatter_types = \Drupal::service('plugin.manager.field.formatter')->getDefinitions();
ksort($formatter_types);
$output['formatter_types'] = array('#markup' => kprint_r($formatter_types, TRUE, $this->t('Formatter types')));
$widget_types = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
ksort($widget_types);
$output['widget_types'] = array('#markup' => kprint_r($widget_types, TRUE, $this->t('Widget types')));
return $output;
}
示例5: get
/**
* Responds to GET requests.
*
* Returns a list of bundles for specified entity.
*
* @return \Drupal\rest\ResourceResponse
* The response containing a reponse HTML.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function get($entity = NULL, $bundle = NULL)
{
if ($entity && $bundle) {
$permission = 'Administer content types';
if (!$this->currentUser->hasPermission($permission)) {
throw new AccessDeniedHttpException();
}
// Query by filtering on the ID by entity and bundle.
$ids = \Drupal::entityQuery('field_config')->condition('id', $entity . '.' . $bundle . '.', 'STARTS_WITH')->execute();
// Fetch all fields and key them by field name.
$field_configs = FieldConfig::loadMultiple($ids);
$fields = array();
foreach ($field_configs as $field_instance) {
$fields[$field_instance->getName()] = $field_instance;
}
if (!empty($fields)) {
return new ResourceResponse($fields);
}
throw new NotFoundHttpException(t('Field for entity @entity and bundle @bundle were not found', array('@entity' => $entity, '@bundle' => $bundle)));
}
// Throw an exception if it is required.
throw new HttpException(t('Entity and Bundle weren\'t provided'));
}
示例6: testExportImport
/**
* Tests a simple site export import case.
*/
public function testExportImport()
{
// After installation there is no snapshot and nothing to import.
$this->drupalGet('admin/config/development/configuration');
$this->assertNoText(t('Warning message'));
$this->assertText(t('There are no configuration changes to import.'));
$this->originalSlogan = $this->config('system.site')->get('slogan');
$this->newSlogan = $this->randomString(16);
$this->assertNotEqual($this->newSlogan, $this->originalSlogan);
$this->config('system.site')->set('slogan', $this->newSlogan)->save();
$this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
// Create a content type.
$this->contentType = $this->drupalCreateContentType();
// Create a field.
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text'));
$this->fieldStorage->save();
entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->contentType->id()))->save();
// Update the displays so that configuration does not change unexpectedly on
// import.
entity_get_form_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName, array('type' => 'text_textfield'))->save();
entity_get_display('node', $this->contentType->id(), 'full')->setComponent($this->fieldName)->save();
entity_get_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName)->save();
entity_get_display('node', $this->contentType->id(), 'teaser')->removeComponent($this->fieldName)->save();
$this->drupalGet('node/add/' . $this->contentType->id());
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
// Export the configuration.
$this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
$this->tarball = $this->getRawContent();
$this->config('system.site')->set('slogan', $this->originalSlogan)->save();
$this->assertEqual($this->config('system.site')->get('slogan'), $this->originalSlogan);
// Delete the custom field.
$fields = FieldConfig::loadMultiple();
foreach ($fields as $field) {
if ($field->getName() == $this->fieldName) {
$field->delete();
}
}
$field_storages = FieldStorageConfig::loadMultiple();
foreach ($field_storages as $field_storage) {
if ($field_storage->getName() == $this->fieldName) {
$field_storage->delete();
}
}
$this->drupalGet('node/add/' . $this->contentType->id());
$this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed');
// Import the configuration.
$filename = 'temporary://' . $this->randomMachineName();
file_put_contents($filename, $this->tarball);
$this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
// There is no snapshot yet because an import has never run.
$this->assertNoText(t('Warning message'));
$this->assertNoText(t('There are no configuration changes to import.'));
$this->assertText($this->contentType->label());
$this->drupalPostForm(NULL, array(), 'Import all');
// After importing the snapshot has been updated an there are no warnings.
$this->assertNoText(t('Warning message'));
$this->assertText(t('There are no configuration changes to import.'));
$this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
$this->drupalGet('node/add');
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
$this->config('system.site')->set('slogan', $this->originalSlogan)->save();
$this->drupalGet('admin/config/development/configuration');
$this->assertText(t('Warning message'));
$this->assertText('The following items in your active configuration have changes since the last import that may be lost on the next import.');
// Ensure the item is displayed as part of a list (to avoid false matches
// on the rest of the page) and that the list markup is not escaped.
$this->assertRaw('<li>system.site</li>');
// Remove everything from staging. The warning about differences between the
// active and snapshot should no longer exist.
\Drupal::service('config.storage.staging')->deleteAll();
$this->drupalGet('admin/config/development/configuration');
$this->assertNoText(t('Warning message'));
$this->assertNoText('The following items in your active configuration have changes since the last import that may be lost on the next import.');
$this->assertText(t('There are no configuration changes to import.'));
// Write a file to staging. The warning about differences between the
// active and snapshot should now exist.
/** @var \Drupal\Core\Config\StorageInterface $staging */
$staging = $this->container->get('config.storage.staging');
$data = $this->config('system.site')->get();
$data['slogan'] = 'in the face';
$this->copyConfig($this->container->get('config.storage'), $staging);
$staging->write('system.site', $data);
$this->drupalGet('admin/config/development/configuration');
$this->assertText(t('Warning message'));
$this->assertText('The following items in your active configuration have changes since the last import that may be lost on the next import.');
// Ensure the item is displayed as part of a list (to avoid false matches
// on the rest of the page) and that the list markup is not escaped.
$this->assertRaw('<li>system.site</li>');
}
示例7: testExportImport
/**
* Tests a simple site export import case.
*/
public function testExportImport()
{
// After installation there is no snapshot and nothing to import.
$this->drupalGet('admin/config/development/configuration');
$this->assertNoText(t('Warning message'));
$this->assertText(t('There are no configuration changes to import.'));
$this->originalSlogan = $this->config('system.site')->get('slogan');
$this->newSlogan = $this->randomString(16);
$this->assertNotEqual($this->newSlogan, $this->originalSlogan);
$this->config('system.site')->set('slogan', $this->newSlogan)->save();
$this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
// Create a content type.
$this->contentType = $this->drupalCreateContentType();
// Create a field.
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text'));
$this->fieldStorage->save();
entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->contentType->id()))->save();
// Update the displays so that configuration does not change unexpectedly on
// import.
entity_get_form_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName, array('type' => 'text_textfield'))->save();
entity_get_display('node', $this->contentType->id(), 'full')->setComponent($this->fieldName)->save();
entity_get_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName)->save();
entity_get_display('node', $this->contentType->id(), 'teaser')->removeComponent($this->fieldName)->save();
$this->drupalGet('node/add/' . $this->contentType->id());
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
// Export the configuration.
$this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
$this->tarball = $this->getRawContent();
$this->config('system.site')->set('slogan', $this->originalSlogan)->save();
$this->assertEqual($this->config('system.site')->get('slogan'), $this->originalSlogan);
// Delete the custom field.
$fields = FieldConfig::loadMultiple();
foreach ($fields as $field) {
if ($field->field_name == $this->fieldName) {
$field->delete();
}
}
$field_storages = FieldStorageConfig::loadMultiple();
foreach ($field_storages as $field_storage) {
if ($field_storage->getName() == $this->fieldName) {
$field_storage->delete();
}
}
$this->drupalGet('node/add/' . $this->contentType->id());
$this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed');
// Import the configuration.
$filename = 'temporary://' . $this->randomMachineName();
file_put_contents($filename, $this->tarball);
$this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
// There is no snapshot yet because an import has never run.
$this->assertNoText(t('Warning message'));
$this->assertNoText(t('There are no configuration changes to import.'));
$this->assertText($this->contentType->label());
$this->drupalPostForm(NULL, array(), 'Import all');
// After importing the snapshot has been updated an there are no warnings.
$this->assertNoText(t('Warning message'));
$this->assertText(t('There are no configuration changes to import.'));
$this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
$this->drupalGet('node/add');
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
$this->config('system.site')->set('slogan', $this->originalSlogan)->save();
$this->drupalGet('admin/config/development/configuration');
$this->assertText(t('Warning message'));
$this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site');
// Remove everything from staging. The warning about differences between the
// active and snapshot should still exist.
\Drupal::service('config.storage.staging')->deleteAll();
$this->drupalGet('admin/config/development/configuration');
$this->assertText(t('Warning message'));
$this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site');
$this->assertText(t('There are no configuration changes to import.'));
}
示例8: getFields
/**
* {@inheritdoc}
*/
public function getFields()
{
// Default fields.
$facet_fields = $this->getDefaultFields();
// Get the allowed field types.
$allowed_field_types = \Drupal::moduleHandler()->invokeAll('facets_core_allowed_field_types', array($field_types = []));
// Get the current field instances and detect if the field type is allowed.
$fields = FieldConfig::loadMultiple();
/** @var \Drupal\Field\FieldConfigInterface $field */
foreach ($fields as $field) {
// Verify if the target type is allowed for entity reference fields,
// otherwise verify the field type (that is, integer, float...).
$target_is_allowed = in_array($field->getFieldStorageDefinition()->getSetting('target_type'), $allowed_field_types);
$field_is_allowed = in_array($field->getFieldStorageDefinition()->getType(), $allowed_field_types);
if ($target_is_allowed || $field_is_allowed) {
/** @var \Drupal\field\Entity\FieldConfig $field */
if (!array_key_exists($field->getName(), $facet_fields)) {
$facet_fields[$field->getName()] = $this->t('@label', ['@label' => $field->getLabel()]);
}
}
}
return $facet_fields;
}
示例9: checkUploadExtensions
/**
* Check upload extensions
* @param null $last_check
* @return array
*/
private function checkUploadExtensions($last_check = NULL)
{
$check_result = TRUE;
$check_result_value = array();
$unsafe_extensions = $this->unsafeExtensions();
$fields = FieldConfig::loadMultiple();
foreach ($fields as $field_name => $field) {
$dependencies = $field->get('dependencies');
if (isset($dependencies) && !empty($dependencies['module'])) {
foreach ($dependencies['module'] as $module) {
if ($module == 'image' || $module == 'file') {
foreach ($unsafe_extensions as $unsafe_extension) {
// Check instance file_extensions.
if (strpos($field->settings['file_extensions'], $unsafe_extension) !== FALSE) {
// Found an unsafe extension.
$check_result_value[$field->field_name][$field->bundle] = $unsafe_extension;
$check_result = FALSE;
}
}
}
}
}
}
return array('result' => $check_result, 'value' => $check_result_value);
}