Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,7 @@
field.formatter.settings.field_plugins_test_text_formatter:
type: field.formatter.settings.text_trimmed
label: 'Test text formatter display format settings'
field.widget.settings.field_plugins_test_text_widget:
type: field.widget.settings.text_textfield
label: 'Test text field widget settings'

View file

@ -0,0 +1,8 @@
name: 'Field Plugins Test'
type: module
description: 'Support module for the field and entity display tests.'
core: 8.x
package: Testing
version: VERSION
dependencies:
- text

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\field_plugins_test\Plugin\Field\FieldFormatter;
use Drupal\text\Plugin\Field\FieldFormatter\TextTrimmedFormatter;
/**
* Plugin implementation of the 'field_plugins_test_text_formatter' formatter.
*
* @FieldFormatter(
* id = "field_plugins_test_text_formatter",
* label = @Translation("Test Trimmed"),
* field_types = {
* "text",
* "text_long",
* "text_with_summary"
* },
* quickedit = {
* "editor" = "form"
* }
* )
*/
class TestTextTrimmedFormatter extends TextTrimmedFormatter {
}

View file

@ -0,0 +1,20 @@
<?php
namespace Drupal\field_plugins_test\Plugin\Field\FieldWidget;
use Drupal\text\Plugin\Field\FieldWidget\TextfieldWidget;
/**
* Plugin implementation of the 'field_plugins_test_text_widget' widget.
*
* @FieldWidget(
* id = "field_plugins_test_text_widget",
* label = @Translation("Test Text field"),
* field_types = {
* "text",
* "string"
* },
* )
*/
class TestTextfieldWidget extends TextfieldWidget {
}

View file

@ -0,0 +1,139 @@
field.formatter.settings.field_test_default:
type: mapping
label: 'Field test default display format settings'
mapping:
test_formatter_setting:
type: string
label: 'Test setting'
field.formatter.settings.field_test_multiple:
type: mapping
label: 'Multiple field test display format settings'
mapping:
test_formatter_setting_multiple:
type: string
label: 'Test setting'
alter:
type: boolean
label: 'Test altering'
field.formatter.settings.field_empty_setting:
type: mapping
label: 'Empty setting field display format settings'
mapping:
field_empty_setting:
type: string
label: 'Test setting'
field.formatter.settings.field_test_with_prepare_view:
type: mapping
label: 'Field prepare step display format settings'
mapping:
test_formatter_setting_additional:
type: string
label: 'Test setting'
field.widget.settings.test_field_widget:
type: mapping
label: 'Test field widget settings'
mapping:
test_widget_setting:
type: string
label: 'Test setting'
role:
type: string
label: 'A referenced role'
role2:
type: string
label: 'A 2nd referenced role'
field.widget.settings.test_field_widget_multiple:
type: mapping
label: 'Test multiple field widget settings'
mapping:
test_widget_setting_multiple:
type: string
label: 'Test setting'
field.widget.third_party.color:
type: mapping
label: 'Field test entity display color module third party settings'
mapping:
foo:
type: string
label: 'Foo setting'
field.storage_settings.test_field:
type: mapping
label: 'Test field storage settings'
mapping:
test_field_storage_setting:
type: string
label: 'Test field storage setting'
changeable:
type: string
label: 'A changeable field storage setting'
unchangeable:
type: string
label: 'An unchangeable field storage setting'
config_data_from_storage_setting:
type: boolean
label: 'Test FieldItemInterface::storageSettingsToConfigData()'
translatable_storage_setting:
type: label
label: 'Translatable storage setting'
field.storage_settings.test_field_with_dependencies:
type: field.storage_settings.test_field
label: 'Test field with dependencies storage settings'
field.storage_settings.hidden_test_field:
type: field.storage_settings.test_field
label: 'Hidden test field storage settings'
field.storage_settings.test_field_with_preconfigured_options:
type: field.storage_settings.test_field
label: 'Test field with preconfigured options storage settings'
field.field_settings.test_field:
type: mapping
label: 'Test field field settings'
mapping:
test_field_setting:
type: string
label: 'Test field setting'
config_data_from_field_setting:
type: boolean
label: 'Test FieldItemInterface::fieldSettingsToConfigData()'
translatable_field_setting:
type: label
label: 'Translatable field setting'
field.field_settings.test_field_with_dependencies:
type: field.field_settings.test_field
label: 'Test field with dependencies field settings'
field.field_settings.hidden_test_field:
type: field.field_settings.test_field
label: 'Hidden test field field settings'
field.field_settings.test_field_with_preconfigured_options:
type: field.field_settings.test_field
label: 'Test field with preconfigured settings'
field.value.test_field:
type: mapping
label: 'Default value'
mapping:
value:
type: label
label: 'Value'
field.formatter.third_party.field_test:
type: mapping
label: 'Field test entity display third party setting'
mapping:
foo:
type: string
label: 'Test setting'

View file

@ -0,0 +1,34 @@
<?php
/**
* @file
* Defines an entity type.
*/
/**
* Implements hook_entity_type_alter().
*/
function field_test_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach (field_test_entity_info_translatable() as $entity_type => $translatable) {
$entity_types[$entity_type]->set('translatable', $translatable);
}
}
/**
* Helper function to enable entity translations.
*/
function field_test_entity_info_translatable($entity_type_id = NULL, $translatable = NULL) {
$stored_value = &drupal_static(__FUNCTION__, array());
if (isset($entity_type_id)) {
$entity_manager = \Drupal::entityManager();
$original = $entity_manager->getDefinition($entity_type_id);
$stored_value[$entity_type_id] = $translatable;
if ($translatable != $original->isTranslatable()) {
$entity_manager->clearCachedDefinitions();
$entity_type = $entity_manager->getDefinition($entity_type_id);
$entity_manager->onEntityTypeUpdate($entity_type, $original);
}
}
return $stored_value;
}

View file

@ -0,0 +1,55 @@
<?php
/**
* @file
* Defines a field type and its formatters and widgets.
*/
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\FieldStorageConfigInterface;
/**
* Implements hook_field_widget_info_alter().
*/
function field_test_field_widget_info_alter(&$info) {
$info['test_field_widget_multiple']['field_types'][] = 'test_field';
$info['test_field_widget_multiple']['field_types'][] = 'test_field_with_preconfigured_options';
}
/**
* Implements hook_field_storage_config_update_forbid().
*/
function field_test_field_storage_config_update_forbid(FieldStorageConfigInterface $field_storage, FieldStorageConfigInterface $prior_field_storage) {
if ($field_storage->getType() == 'test_field' && $field_storage->getSetting('unchangeable') != $prior_field_storage->getSetting('unchangeable')) {
throw new FieldStorageDefinitionUpdateForbiddenException("field_test 'unchangeable' setting cannot be changed'");
}
}
/**
* Sample 'default value' callback.
*/
function field_test_default_value(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
return array(array('value' => 99));
}
/**
* Implements hook_entity_field_access().
*/
function field_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
if ($field_definition->getName() == "field_no_{$operation}_access") {
return AccessResult::forbidden();
}
// Only grant view access to test_view_field fields when the user has
// 'view test_view_field content' permission.
if ($field_definition->getName() == 'test_view_field' && $operation == 'view') {
return AccessResult::forbiddenIf(!$account->hasPermission('view test_view_field content'))->cachePerPermissions();
}
return AccessResult::allowed();
}

View file

@ -0,0 +1,8 @@
name: 'Field API Test'
type: module
description: 'Support module for the Field API tests.'
core: 8.x
package: Testing
version: VERSION
dependencies:
- entity_test

View file

@ -0,0 +1,170 @@
<?php
/**
* @file
* Helper module for the Field API tests.
*
* The module defines
* - an entity type (field_test.entity.inc)
* - a field type and its formatters and widgets (field_test.field.inc)
* - a field storage backend (field_test.storage.inc)
*
* The main field_test.module file implements generic hooks and provides some
* test helper functions
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\FieldStorageConfigInterface;
require_once __DIR__ . '/field_test.entity.inc';
require_once __DIR__ . '/field_test.field.inc';
/**
* Store and retrieve keyed data for later verification by unit tests.
*
* This function is a simple in-memory key-value store with the
* distinction that it stores all values for a given key instead of
* just the most recently set value. field_test module hooks call
* this function to record their arguments, keyed by hook name. The
* unit tests later call this function to verify that the correct
* hooks were called and were passed the correct arguments.
*
* This function ignores all calls until the first time it is called
* with $key of NULL. Each time it is called with $key of NULL, it
* erases all previously stored data from its internal cache, but also
* returns the previously stored data to the caller. A typical usage
* scenario is:
*
* @code
* // calls to field_test_memorize() here are ignored
*
* // turn on memorization
* field_test_memorize();
*
* // call some Field API functions that invoke field_test hooks
* FieldStorageConfig::create($field_definition)->save();
*
* // retrieve and reset the memorized hook call data
* $mem = field_test_memorize();
*
* // make sure hook_field_storage_config_create() is invoked correctly
* assertEqual(count($mem['field_test_field_storage_config_create']), 1);
* assertEqual($mem['field_test_field_storage_config_create'][0], array($field));
* @endcode
*
* @param $key
* The key under which to store to $value, or NULL as described above.
* @param $value
* A value to store for $key.
* @return
* An array mapping each $key to an array of each $value passed in
* for that key.
*/
function field_test_memorize($key = NULL, $value = NULL) {
$memorize = &drupal_static(__FUNCTION__, NULL);
if (!isset($key)) {
$return = $memorize;
$memorize = array();
return $return;
}
if (is_array($memorize)) {
$memorize[$key][] = $value;
}
}
/**
* Memorize calls to field_test_field_storage_config_create().
*/
function field_test_field_storage_config_create(FieldStorageConfigInterface $field_storage) {
$args = func_get_args();
field_test_memorize(__FUNCTION__, $args);
}
/**
* Implements hook_entity_display_build_alter().
*/
function field_test_entity_display_build_alter(&$output, $context) {
$display_options = $context['display']->getComponent('test_field');
if (isset($display_options['settings']['alter'])) {
$output['test_field'][] = array('#markup' => 'field_test_entity_display_build_alter');
}
if (isset($output['test_field'])) {
$output['test_field'][] = array('#markup' => 'entity language is ' . $context['entity']->language()->getId());
}
}
/**
* Implements hook_field_widget_form_alter().
*/
function field_test_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
$field_definition = $context['items']->getFieldDefinition();
switch ($field_definition->getName()) {
case 'alter_test_text':
drupal_set_message('Field size: ' . $context['widget']->getSetting('size'));
break;
case 'alter_test_options':
drupal_set_message('Widget type: ' . $context['widget']->getPluginId());
break;
}
// Set a message if this is for the form displayed to set default value for
// the field.
if ($context['default']) {
drupal_set_message('From hook_field_widget_form_alter(): Default form is true.');
}
}
/**
* Implements hook_query_TAG_alter() for tag 'efq_table_prefixing_test'.
*
* @see \Drupal\system\Tests\Entity\EntityFieldQueryTest::testTablePrefixing()
*/
function field_test_query_efq_table_prefixing_test_alter(&$query) {
// Add an additional join onto the entity base table. This will cause an
// exception if the EFQ does not properly prefix the base table.
$query->join('entity_test', 'et2', '%alias.id = entity_test.id');
}
/**
* Implements hook_query_TAG_alter() for tag 'efq_metadata_test'.
*
* @see \Drupal\system\Tests\Entity\EntityQueryTest::testMetaData()
*/
function field_test_query_efq_metadata_test_alter(&$query) {
global $efq_test_metadata;
$efq_test_metadata = $query->getMetadata('foo');
}
/**
* Implements hook_entity_extra_field_info_alter().
*/
function field_test_entity_extra_field_info_alter(&$info) {
// Remove all extra fields from the 'no_fields' content type;
unset($info['node']['no_fields']);
}
/**
* Implements hook_entity_bundle_field_info_alter().
*/
function field_test_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
if (($field_name = \Drupal::state()->get('field_test_set_constraint', FALSE)) && $entity_type->id() == 'entity_test' && $bundle == 'entity_test' && !empty($fields[$field_name])) {
$fields[$field_name]->setPropertyConstraints('value', [
'Range' => [
'min' => 0,
'max' => 32,
],
]);
}
if (($field_name = \Drupal::state()->get('field_test_add_constraint', FALSE)) && $entity_type->id() == 'entity_test' && $bundle == 'entity_test' && !empty($fields[$field_name])) {
$fields[$field_name]->addPropertyConstraints('value', [
'Range' => [
'min' => 0,
'max' => 32,
],
]);
}
}

View file

@ -0,0 +1,6 @@
view test_view_field content:
title: 'View test field content'
description: 'View published test_view_field content.'
administer field_test content:
title: 'Administer field_test content'
description: 'Manage field_test content'

View file

@ -0,0 +1,27 @@
field_test.entity_nested_form:
path: '/test-entity/nested/{entity_1}/{entity_2}'
defaults:
_title: 'Nested entity form'
_form: '\Drupal\field_test\Form\NestedEntityTestForm'
options:
parameters:
entity_1:
type: 'entity:entity_test'
entity_2:
type: 'entity:entity_test'
requirements:
_permission: 'administer entity_test content'
field_test.entity_constraints_nested_form:
path: '/test-entity-constraints/nested/{entity_1}/{entity_2}'
defaults:
_title: 'Nested entity form'
_form: '\Drupal\field_test\Form\NestedEntityTestForm'
options:
parameters:
entity_1:
type: 'entity:entity_test_constraints'
entity_2:
type: 'entity:entity_test_constraints'
requirements:
_permission: 'administer entity_test content'

View file

@ -0,0 +1,107 @@
<?php
namespace Drupal\field_test\Form;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
/**
* Provides a form for field_test routes.
*/
class NestedEntityTestForm extends FormBase {
/**
* {@inheritdoc]
*/
public function getFormId() {
return 'field_test_entity_nested_form';
}
/**
* {@inheritdoc]
*/
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity_1 = NULL, EntityInterface $entity_2 = NULL) {
// First entity.
$form_state->set('entity_1', $entity_1);
$form_display_1 = EntityFormDisplay::collectRenderDisplay($entity_1, 'default');
$form_state->set('form_display_1', $form_display_1);
$form_display_1->buildForm($entity_1, $form, $form_state);
// Second entity.
$form_state->set('entity_2', $entity_2);
$form_display_2 = EntityFormDisplay::collectRenderDisplay($entity_2, 'default');
$form_state->set('form_display_2', $form_display_2);
$form['entity_2'] = [
'#type' => 'details',
'#title' => t('Second entity'),
'#tree' => TRUE,
'#parents' => ['entity_2'],
'#weight' => 50,
'#attributes' => ['class' => ['entity-2']]
];
$form_display_2->buildForm($entity_2, $form['entity_2'], $form_state);
if ($entity_2 instanceof EntityChangedInterface) {
// Changed must be sent to the client, for later overwrite error checking.
// @see Drupal\field\Tests\NestedFormTest::testNestedEntityFormEntityLevelValidation()
$form['entity_2']['changed'] = [
'#type' => 'hidden',
'#default_value' => $entity_1->getChangedTime(),
];
}
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 100,
);
return $form;
}
/**
* {@inheritdoc]
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$entity_1 = $form_state->get('entity_1');
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display_1 */
$form_display_1 = $form_state->get('form_display_1');
$form_display_1->extractFormValues($entity_1, $form, $form_state);
$form_display_1->validateFormValues($entity_1, $form, $form_state);
$entity_2 = $form_state->get('entity_2');
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display_2 */
$form_display_2 = $form_state->get('form_display_2');
$extracted = $form_display_2->extractFormValues($entity_2, $form['entity_2'], $form_state);
// Extract the values of fields that are not rendered through widgets, by
// simply copying from top-level form values. This leaves the fields that
// are not being edited within this form untouched.
// @see Drupal\field\Tests\NestedFormTest::testNestedEntityFormEntityLevelValidation()
foreach ($form_state->getValues()['entity_2'] as $name => $values) {
if ($entity_2->hasField($name) && !isset($extracted[$name])) {
$entity_2->set($name, $values);
}
}
$form_display_2->validateFormValues($entity_2, $form['entity_2'], $form_state);
}
/**
* {@inheritdoc]
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\EntityInterface $entity_1 */
$entity_1 = $form_state->get('entity_1');
$entity_1->save();
/** @var \Drupal\Core\Entity\EntityInterface $entity_2 */
$entity_2 = $form_state->get('entity_2');
$entity_2->save();
drupal_set_message($this->t('test_entities @id_1 and @id_2 have been updated.', array('@id_1' => $entity_1->id(), '@id_2' => $entity_2->id())));
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
/**
* Plugin implementation of the 'field_test_applicable' formatter.
*
* It is applicable to test_field fields unless their name is 'deny_applicable'.
*
* @FieldFormatter(
* id = "field_test_applicable",
* label = @Translation("Applicable"),
* description = @Translation("Applicable formatter"),
* field_types = {
* "test_field"
* },
* weight = 15,
* )
*/
class TestFieldApplicableFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return $field_definition->getName() != 'deny_applicable';
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
return array('#markup' => 'Nothing to see here');
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'field_test_default' formatter.
*
* @FieldFormatter(
* id = "field_test_default",
* label = @Translation("Default"),
* description = @Translation("Default formatter"),
* field_types = {
* "test_field",
* "test_field_with_preconfigured_options"
* },
* weight = 1
* )
*/
class TestFieldDefaultFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'test_formatter_setting' => 'dummy test string',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_formatter_setting'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this->getSetting('test_formatter_setting'),
'#required' => TRUE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting')));
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array('#markup' => $this->getSetting('test_formatter_setting') . '|' . $item->value);
}
return $elements;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
/**
* Plugin implementation of the 'field_empty_test' formatter.
*
* @FieldFormatter(
* id = "field_empty_test",
* label = @Translation("Field empty test"),
* field_types = {
* "test_field",
* },
* weight = -5
* )
*/
class TestFieldEmptyFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'test_empty_string' => '**EMPTY FIELD**',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
if ($items->isEmpty()) {
// For fields with no value, just add the configured "empty" value.
$elements[0] = array('#markup' => $this->getSetting('test_empty_string'));
}
else {
foreach ($items as $delta => $item) {
// This formatter only needs to output raw for testing.
$elements[$delta] = array('#markup' => $item->value);
}
}
return $elements;
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'field_empty_setting' formatter.
*
* @FieldFormatter(
* id = "field_empty_setting",
* label = @Translation("Field empty setting"),
* field_types = {
* "test_field",
* },
* weight = -1
* )
*/
class TestFieldEmptySettingFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'field_empty_setting' => '',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['field_empty_setting'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this->getSetting('field_empty_setting'),
'#required' => TRUE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$setting = $this->getSetting('field_empty_setting');
if (!empty($setting)) {
$summary[] = t('Default empty setting now has a value.');
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
if (!empty($items)) {
foreach ($items as $delta => $item) {
$elements[$delta] = array('#markup' => $this->getSetting('field_empty_setting'));
}
}
return $elements;
}
}

View file

@ -0,0 +1,75 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'field_test_multiple' formatter.
*
* @FieldFormatter(
* id = "field_test_multiple",
* label = @Translation("Multiple"),
* description = @Translation("Multiple formatter"),
* field_types = {
* "test_field",
* "test_field_with_preconfigured_options"
* },
* weight = 5
* )
*/
class TestFieldMultipleFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'test_formatter_setting_multiple' => 'dummy test string',
'alter' => FALSE,
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_formatter_setting_multiple'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this->getSetting('test_formatter_setting_multiple'),
'#required' => TRUE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple')));
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
if (!empty($items)) {
$array = array();
foreach ($items as $delta => $item) {
$array[] = $delta . ':' . $item->value;
}
$elements[0] = array('#markup' => $this->getSetting('test_formatter_setting_multiple') . '|' . implode('|', $array));
}
return $elements;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
/**
* Plugin implementation of the 'field_no_settings' formatter.
*
* @FieldFormatter(
* id = "field_no_settings",
* label = @Translation("Field no settings"),
* field_types = {
* "test_field",
* },
* weight = -10
* )
*/
class TestFieldNoSettingsFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($items as $delta => $item) {
// This formatter only needs to output raw for testing.
$elements[$delta] = array('#markup' => $item->value);
}
return $elements;
}
}

View file

@ -0,0 +1,83 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'field_test_with_prepare_view' formatter.
*
* @FieldFormatter(
* id = "field_test_with_prepare_view",
* label = @Translation("With prepare step"),
* description = @Translation("Tests prepareView() method"),
* field_types = {
* "test_field"
* },
* weight = 10
* )
*/
class TestFieldPrepareViewFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'test_formatter_setting_additional' => 'dummy test string',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_formatter_setting_additional'] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $this->getSetting('test_formatter_setting_additional'),
'#required' => TRUE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional')));
return $summary;
}
/**
* {@inheritdoc}
*/
public function prepareView(array $entities_items) {
foreach ($entities_items as $items) {
foreach ($items as $item) {
// Don't add anything on empty values.
if (!$item->isEmpty()) {
$item->additional_formatter_value = $item->value + 1;
}
}
}
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array('#markup' => $this->getSetting('test_formatter_setting_additional') . '|' . $item->value . '|' . $item->additional_formatter_value);
}
return $elements;
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldType;
/**
* Defines the 'hidden_test' entity field item.
*
* @FieldType(
* id = "hidden_test_field",
* label = @Translation("Hidden from UI test field"),
* description = @Translation("Dummy hidden field type used for tests."),
* no_ui = TRUE,
* default_widget = "test_field_widget",
* default_formatter = "field_test_default"
* )
*/
class HiddenTestItem extends TestItem {
}

View file

@ -0,0 +1,173 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Field\FieldItemBase;
/**
* Defines the 'test_field' entity field item.
*
* @FieldType(
* id = "test_field",
* label = @Translation("Test field"),
* description = @Translation("Dummy field type used for tests."),
* default_widget = "test_field_widget",
* default_formatter = "field_test_default"
* )
*/
class TestItem extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function defaultStorageSettings() {
return array(
'test_field_storage_setting' => 'dummy test string',
'changeable' => 'a changeable field storage setting',
'unchangeable' => 'an unchangeable field storage setting',
'translatable_storage_setting' => 'a translatable field storage setting',
) + parent::defaultStorageSettings();
}
/**
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
return array(
'test_field_setting' => 'dummy test string',
'translatable_field_setting' => 'a translatable field setting',
) + parent::defaultFieldSettings();
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('integer')
->setLabel(t('Test integer value'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
'type' => 'int',
'size' => 'medium',
),
),
'indexes' => array(
'value' => array('value'),
),
);
}
/**
* {@inheritdoc}
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$form['test_field_storage_setting'] = array(
'#type' => 'textfield',
'#title' => t('Field test field storage setting'),
'#default_value' => $this->getSetting('test_field_storage_setting'),
'#required' => FALSE,
'#description' => t('A dummy form element to simulate field storage setting.'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form['test_field_setting'] = array(
'#type' => 'textfield',
'#title' => t('Field test field setting'),
'#default_value' => $this->getSetting('test_field_setting'),
'#required' => FALSE,
'#description' => t('A dummy form element to simulate field setting.'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function delete() {
// Reports that delete() method is executed for testing purposes.
field_test_memorize('field_test_field_delete', array($this->getEntity()));
}
/**
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', array(
'value' => array(
'TestField' => array(
'value' => -1,
'message' => t('%name does not accept the value @value.', array('%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1)),
)
),
));
return $constraints;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
return empty($this->value);
}
/**
* {@inheritdoc}
*/
public static function storageSettingsToConfigData(array $settings) {
$settings['config_data_from_storage_setting'] = 'TRUE';
unset($settings['storage_setting_from_config_data']);
return $settings;
}
/**
* {@inheritdoc}
*/
public static function storageSettingsFromConfigData(array $settings) {
$settings['storage_setting_from_config_data'] = 'TRUE';
unset($settings['config_data_from_storage_setting']);
return $settings;
}
/**
* {@inheritdoc}
*/
public static function fieldSettingsToConfigData(array $settings) {
$settings['config_data_from_field_setting'] = 'TRUE';
unset($settings['field_setting_from_config_data']);
return $settings;
}
/**
* {@inheritdoc}
*/
public static function fieldSettingsFromConfigData(array $settings) {
$settings['field_setting_from_config_data'] = 'TRUE';
unset($settings['config_data_from_field_setting']);
return $settings;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the 'test_field_with_dependencies' entity field item.
*
* @FieldType(
* id = "test_field_with_dependencies",
* label = @Translation("Test field with dependencies"),
* description = @Translation("Dummy field type used for tests."),
* default_widget = "test_field_widget",
* default_formatter = "field_test_default",
* config_dependencies = {
* "module" = {
* "test_module"
* }
* }
* )
*/
class TestItemWithDependencies extends TestItem {
/**
* {@inheritdoc}
*/
public static function calculateDependencies(FieldDefinitionInterface $field_definition) {
return ['content' => ['node:article:uuid']];
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface;
/**
* Defines the 'test_field_with_preconfigured_options' entity field item.
*
* @FieldType(
* id = "test_field_with_preconfigured_options",
* label = @Translation("Test field with preconfigured options"),
* description = @Translation("Dummy field type used for tests."),
* default_widget = "test_field_widget",
* default_formatter = "field_test_default"
* )
*/
class TestItemWithPreconfiguredOptions extends TestItem implements PreconfiguredFieldUiOptionsInterface {
/**
* {@inheritdoc}
*/
public static function getPreconfiguredOptions() {
return [
'custom_options' => [
'label' => t('All custom options'),
'category' => t('Custom category'),
'field_storage_config' => [
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'test_field_storage_setting' => 'preconfigured_storage_setting'
],
],
'field_config' => [
'required' => TRUE,
'settings' => [
'test_field_setting' => 'preconfigured_field_setting',
],
],
'entity_form_display' => [
'type' => 'test_field_widget_multiple',
],
'entity_view_display' => [
'type' => 'field_test_multiple',
],
],
];
}
}

View file

@ -0,0 +1,62 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Field\FieldItemBase;
/**
* Defines the 'test_object_field' entity field item.
*
* @FieldType(
* id = "test_object_field",
* label = @Translation("Test object field"),
* description = @Translation("Test field type that has an object to test serialization"),
* default_widget = "test_object_field_widget",
* default_formatter = "object_field_test_default"
* )
*/
class TestObjectItem extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('any')
->setLabel(t('Value'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'description' => 'The object item value.',
'type' => 'blob',
'not null' => TRUE,
'serialize' => TRUE,
],
],
];
}
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE) {
if (isset($values['value'])) {
// @todo Remove this in https://www.drupal.org/node/2788637.
if (is_string($values['value'])) {
$values['value'] = unserialize($values['value']);
}
}
parent::setValue($values, $notify);
}
}

View file

@ -0,0 +1,116 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
/**
* Plugin implementation of the 'test_field_widget' widget.
*
* @FieldWidget(
* id = "test_field_widget",
* label = @Translation("Test widget"),
* field_types = {
* "test_field",
* "hidden_test_field",
* "test_field_with_preconfigured_options"
* },
* weight = -10
* )
*/
class TestFieldWidget extends WidgetBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'test_widget_setting' => 'dummy test string',
'role' => 'anonymous',
'role2' => 'anonymous',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_widget_setting'] = array(
'#type' => 'textfield',
'#title' => t('Field test field widget setting'),
'#description' => t('A dummy form element to simulate field widget setting.'),
'#default_value' => $this->getSetting('test_widget_setting'),
'#required' => FALSE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_widget_setting', '@value' => $this->getSetting('test_widget_setting')));
return $summary;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element += array(
'#type' => 'textfield',
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : '',
);
return array('value' => $element);
}
/**
* {@inheritdoc}
*/
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
return $element['value'];
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
foreach (['role', 'role2'] as $setting) {
if (!empty($role_id = $this->getSetting($setting))) {
// Create a dependency on the role config entity referenced in settings.
$dependencies['config'][] = "user.role.$role_id";
}
}
return $dependencies;
}
/**
* {@inheritdoc}
*/
public function onDependencyRemoval(array $dependencies) {
$changed = parent::onDependencyRemoval($dependencies);
// Only the setting 'role' is resolved here. When the dependency related to
// this setting is removed, is expected that the widget component will be
// update accordingly in the display entity. The 'role2' setting is
// deliberately left out from being updated. When the dependency
// corresponding to this setting is removed, is expected that the widget
// component will be disabled in the display entity.
if (!empty($role_id = $this->getSetting('role'))) {
if (!empty($dependencies['config']["user.role.$role_id"])) {
$this->setSetting('role', 'anonymous');
$changed = TRUE;
}
}
return $changed;
}
}

View file

@ -0,0 +1,104 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
/**
* Plugin implementation of the 'test_field_widget_multiple' widget.
*
* The 'field_types' entry is left empty, and is populated through
* hook_field_widget_info_alter().
*
* @see field_test_field_widget_info_alter()
*
* @FieldWidget(
* id = "test_field_widget_multiple",
* label = @Translation("Test widget - multiple"),
* multiple_values = TRUE,
* weight = 10
* )
*/
class TestFieldWidgetMultiple extends WidgetBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'test_widget_setting_multiple' => 'dummy test string',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['test_widget_setting_multiple'] = array(
'#type' => 'textfield',
'#title' => t('Field test field widget setting'),
'#description' => t('A dummy form element to simulate field widget setting.'),
'#default_value' => $this->getSetting('test_widget_setting_multiple'),
'#required' => FALSE,
);
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = t('@setting: @value', array('@setting' => 'test_widget_setting_multiple', '@value' => $this->getSetting('test_widget_setting_multiple')));
return $summary;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$values = array();
foreach ($items as $item) {
$values[] = $item->value;
}
$element += array(
'#type' => 'textfield',
'#default_value' => implode(', ', $values),
'#element_validate' => array(array(get_class($this), 'multipleValidate')),
);
return $element;
}
/**
* {@inheritdoc}
*/
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
return $element;
}
/**
* Element validation helper.
*/
public static function multipleValidate($element, FormStateInterface $form_state) {
$values = array_map('trim', explode(',', $element['#value']));
$items = array();
foreach ($values as $value) {
$items[] = array('value' => $value);
}
$form_state->setValueForElement($element, $items);
}
/**
* {@inheritdoc}
* Used in \Drupal\field\Tests\EntityReference\EntityReferenceAdminTest::testAvailableFormatters().
*/
public static function isApplicable(FieldDefinitionInterface $field_definition) {
// Returns FALSE if machine name of the field equals field_onewidgetfield.
return $field_definition->getName() != "field_onewidgetfield";
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Drupal\field_test\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraints\NotEqualTo;
/**
* Checks if a value is not equal.
*
* @Constraint(
* id = "TestField",
* label = @Translation("Test Field", context = "Validation"),
* type = { "integer" }
* )
*/
class TestFieldConstraint extends NotEqualTo {
/**
* {@inheritdoc}
*/
public function getRequiredOptions() {
return array('value');
}
/**
* {@inheritdoc}
*/
public function validatedBy() {
return '\Symfony\Component\Validator\Constraints\NotEqualToValidator';
}
}

View file

@ -0,0 +1,8 @@
name: 'Boolean field Test'
type: module
description: 'Support module for the field and entity display tests.'
core: 8.x
package: Testing
version: VERSION
dependencies:
- field

View file

@ -0,0 +1,18 @@
<?php
/**
* @file
* Module for testing denying access to boolean fields.
*/
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Implements hook_entity_field_access().
*/
function field_test_boolean_access_denied_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
return AccessResult::forbiddenIf($field_definition->getName() === \Drupal::state()->get('field.test_boolean_field_access_field'));
}

View file

@ -0,0 +1,15 @@
id: entity_test.entity_test.field_test_import
langcode: en
field_name: field_test_import
entity_type: entity_test
bundle: entity_test
label: 'Test import field'
description: ''
required: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: text
dependencies:
config:
- field.storage.entity_test.field_test_import

View file

@ -0,0 +1,15 @@
id: entity_test.entity_test.field_test_import_2
langcode: en
field_name: field_test_import_2
entity_type: entity_test
bundle: entity_test
label: 'Test import field 2 on entity_test bundle'
description: ''
required: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: text
dependencies:
config:
- field.storage.entity_test.field_test_import_2

View file

@ -0,0 +1,15 @@
id: entity_test.test_bundle.field_test_import_2
langcode: en
field_name: field_test_import_2
entity_type: entity_test
bundle: test_bundle
label: 'Test import field 2 on test bundle'
description: ''
required: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: text
dependencies:
config:
- field.storage.entity_test.field_test_import_2

View file

@ -0,0 +1,20 @@
id: entity_test.field_test_import
langcode: en
field_name: field_test_import
entity_type: entity_test
type: text
settings:
max_length: 255
module: text
locked: false
cardinality: 1
translatable: false
indexes:
format:
- format
dependencies:
module:
- entity_test
- text
persist_with_no_fields: false
custom_storage: false

View file

@ -0,0 +1,20 @@
id: entity_test.field_test_import_2
langcode: en
field_name: field_test_import_2
entity_type: entity_test
type: text
settings:
max_length: 255
module: text
locked: false
cardinality: 1
translatable: false
indexes:
format:
- format
dependencies:
module:
- entity_test
- text
persist_with_no_fields: false
custom_storage: false

View file

@ -0,0 +1,6 @@
name: 'Field API configuration tests'
type: module
description: 'Support module for the Field API configuration tests.'
core: 8.x
package: Testing
version: VERSION

View file

@ -0,0 +1,16 @@
id: entity_test.entity_test.field_test_import_sync
uuid: ea711065-6940-47cd-813d-618f64095481
langcode: en
field_name: field_test_import_sync
entity_type: entity_test
bundle: entity_test
label: 'Import from sync'
description: ''
required: '0'
default_value: { }
default_value_callback: ''
settings: { }
field_type: text
dependencies:
config:
- field.storage.entity_test.field_test_import_sync

View file

@ -0,0 +1,16 @@
id: entity_test.test_bundle.field_test_import_sync_2
uuid: f07794a2-d7cc-45b6-b40d-13cf021b5552
langcode: en
field_name: field_test_import_sync_2
entity_type: entity_test
bundle: test_bundle
label: 'Test import field 2 on test bundle'
description: ''
required: '0'
default_value: { }
default_value_callback: ''
settings: { }
field_type: text
dependencies:
config:
- field.storage.entity_test.field_test_import_sync_2

View file

@ -0,0 +1,16 @@
id: entity_test.test_bundle_2.field_test_import_sync_2
uuid: 49d6dd19-5097-443d-8f00-fc79525bebce
langcode: en
field_name: field_test_import_sync_2
entity_type: entity_test
bundle: test_bundle_2
label: 'Test import field 2 on test bundle 2'
description: ''
required: '0'
default_value: { }
default_value_callback: ''
settings: { }
field_type: text
dependencies:
config:
- field.storage.entity_test.field_test_import_sync_2

View file

@ -0,0 +1,21 @@
id: entity_test.field_test_import_sync
uuid: 0bf654cc-f14a-4881-b94c-76959e47466b
langcode: en
field_name: field_test_import_sync
entity_type: entity_test
type: text
settings:
max_length: '255'
module: text
locked: '0'
cardinality: '1'
translatable: '0'
indexes:
format:
- format
dependencies:
module:
- entity_test
- text
persist_with_no_fields: false
custom_storage: false

View file

@ -0,0 +1,21 @@
id: entity_test.field_test_import_sync_2
uuid: 2165d9aa-9a0c-41a1-be02-2a49f3405c00
langcode: en
field_name: field_test_import_sync_2
entity_type: entity_test
type: text
settings:
max_length: '255'
module: text
locked: '0'
cardinality: '1'
translatable: '0'
indexes:
format:
- format
dependencies:
module:
- entity_test
- text
persist_with_no_fields: false
custom_storage: false

View file

@ -0,0 +1,8 @@
name: 'Field test views'
type: module
description: 'Provides default views for views field tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- views

View file

@ -0,0 +1,52 @@
langcode: en
status: true
dependencies:
module:
- node
- user
config:
- field.storage.node.field_test
id: test_view_field_delete
label: test_view_field_delete
module: views
description: ''
tag: default
base_table: node
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: perm
fields:
nid:
field: nid
id: nid
table: node
plugin_id: field
entity_type: node
entity_field: nid
field_test:
id: field_test
table: node__field_test
field: field_test
plugin_id: field
entity_type: node
entity_field: field_test
cache:
type: tag
exposed_form:
type: basic
pager:
type: full
query:
type: views_query
style:
type: default
row:
type: fields
display_plugin: default
display_title: Master
id: default
position: 0

View file

@ -0,0 +1,64 @@
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_view_fieldapi
label: test_view_fieldapi
module: views
description: ''
tag: default
base_table: node_field_data
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: perm
fields:
nid:
field: nid
id: nid
table: node_field_data
plugin_id: field
entity_type: node
entity_field: nid
field_name_0:
id: field_name_0
table: node__field_name_0
field: field_name_0
plugin_id: field
entity_type: node
entity_field: field_name_0
field_name_5:
id: field_name_5
table: node__field_name_5
field: field_name_5
plugin_id: field
entity_type: node
entity_field: field_name_5
field_no_view_access:
id: field_no_view_access
table: node__field_no_view_access
field: field_no_view_access
plugin_id: field
entity_type: node
entity_field: field_no_view_access
cache:
type: tag
exposed_form:
type: basic
pager:
type: full
query:
type: views_query
style:
type: default
row:
type: fields
display_plugin: default
display_title: Master
id: default
position: 0

View file

@ -0,0 +1,15 @@
field.formatter.third_party.field_third_party_test:
type: mapping
label: 'field_third_party_test third party formatter settings'
mapping:
field_test_field_formatter_third_party_settings_form:
type: string
label: field_test_field_formatter_third_party_settings_form
field.widget.third_party.field_third_party_test:
type: mapping
label: 'field_third_party_test third party widget settings'
mapping:
field_test_widget_third_party_settings_form:
type: string
label: field_test_widget_third_party_settings_form

View file

@ -0,0 +1,9 @@
name: 'Field Third Party Settings Test'
type: module
description: 'Support module for the Field API tests.'
core: 8.x
package: Testing
version: VERSION
dependencies:
- entity_test
- field_test

View file

@ -0,0 +1,51 @@
<?php
/**
* @file
* Test module.
*/
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterInterface;
use Drupal\Core\Field\WidgetInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_field_widget_third_party_settings_form().
*/
function field_third_party_test_field_widget_third_party_settings_form(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state) {
$element['field_test_widget_third_party_settings_form'] = array(
'#type' => 'textfield',
'#title' => t('3rd party widget settings form'),
'#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'),
);
return $element;
}
/**
* Implements hook_field_widget_settings_summary_alter().
*/
function field_third_party_test_field_widget_settings_summary_alter(&$summary, $context) {
$summary[] = 'field_test_field_widget_settings_summary_alter';
return $summary;
}
/**
* Implements hook_field_formatter_third_party_settings_form().
*/
function field_third_party_test_field_formatter_third_party_settings_form(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state) {
$element['field_test_field_formatter_third_party_settings_form'] = array(
'#type' => 'textfield',
'#title' => t('3rd party formatter settings form'),
'#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'),
);
return $element;
}
/**
* Implements hook_field_formatter_settings_summary_alter().
*/
function field_third_party_test_field_formatter_settings_summary_alter(&$summary, $context) {
$summary[] = 'field_test_field_formatter_settings_summary_alter';
return $summary;
}