Commit 239a9bd7 authored by jerdavis's avatar jerdavis

Schema and config updates

parent 0e0aa514
......@@ -7,7 +7,7 @@ field.storage_settings.viewfield:
label: 'Type of item to reference'
field.value.viewfield:
type: mapping
type: field.value.entity_reference
label: 'Default value'
mapping:
target_id:
......@@ -40,6 +40,12 @@ field.field_settings.viewfield:
label: 'Allowed displays'
sequence:
type: string
handler:
type: string
label: 'Reference method'
handler_settings:
type: entity_reference_selection.[%parent.handler]
label: 'Entity reference selection plugin settings'
field.formatter.settings.viewfield_default:
type: mapping
......
......@@ -2,8 +2,10 @@
namespace Drupal\viewfield\Plugin\Field\FieldType;
use Drupal\Core\Entity\ContentEntityStorageInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Field\FieldFilteredMarkup;
......@@ -41,15 +43,14 @@ class ViewfieldItem extends EntityReferenceItem {
'force_default' => 0,
'allowed_views' => [],
'allowed_display_types' => ['block' => 'block'],
];
] + parent::defaultFieldSettings();
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
// $schema = parent::schema($field_definition);
$schema['columns']['target_id']['description'] = 'The ID of the view.';
$schema = parent::schema($field_definition);
$schema['columns']['display_id'] = [
'description' => 'The ID of the view display.',
......
......@@ -13,28 +13,33 @@ class ViewfieldFormatterTest extends ViewfieldFunctionalTestBase {
* Test viewfield_default formatter.
*/
public function testViewfieldFormatterDefault() {
$this->form->setComponent('field_view', [
$this->form->setComponent('field_view_test', [
'type' => 'viewfield_select',
])->save();
$this->display->setComponent('field_view', [
$this->display->setComponent('field_view_test', [
'type' => 'viewfield_default',
'weight' => 1,
'label' => 'hidden',
])->save();
// Display creation form.
$this->drupalGet('node/add/article');
$this->drupalGet('node/add/article_test');
$session = $this->assertSession();
$session->fieldExists("field_view[0][target_id]");
$session->fieldExists("field_view[0][display_id]");
$session->fieldExists("field_view[0][arguments]");
$page = $this->getSession()->getPage();
$session->fieldExists("field_view_test[0][target_id]");
$session->fieldExists("field_view_test[0][display_id]");
$session->fieldExists("field_view_test[0][arguments]");
$page->fillField('field_view_test[0][target_id', 'content_test');
$this->waitForAjaxToFinish();
// Test basic entry of Viewfield.
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_view[0][target_id]' => 'content',
'field_view[0][display_id]' => 'block_1',
'field_view_test[0][display_id]' => 'block_1',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
......@@ -53,34 +58,41 @@ class ViewfieldFormatterTest extends ViewfieldFunctionalTestBase {
* Test Viewfield argument handling.
*/
public function testViewfieldArgumentHandling() {
$this->form->setComponent('field_view', [
$this->form->setComponent('field_view_test', [
'type' => 'viewfield_select',
])->save();
$this->display->setComponent('field_view', [
$this->display->setComponent('field_view_test', [
'type' => 'viewfield_default',
'weight' => 1,
'label' => 'hidden',
])->save();
// Display creation form.
$this->drupalGet('node/add/article');
$this->drupalGet('node/add/article_test');
$session = $this->assertSession();
$session->fieldExists("field_view[0][target_id]");
$session->fieldExists("field_view[0][display_id]");
$session->fieldExists("field_view[0][arguments]");
$page = $this->getSession()->getPage();
$session->fieldExists("field_view_test[0][target_id]");
$session->fieldExists("field_view_test[0][display_id]");
$session->fieldExists("field_view_test[0][arguments]");
$page->fillField('field_view_test[0][target_id', 'content_test');
$this->waitForAjaxToFinish();
// Test argument handling
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_view[0][target_id]' => "content",
'field_view[0][display_id]' => 'block_1',
'field_view[0][arguments]' => 'page',
'field_view_test[0][target_id]' => "content_test",
'field_view_test[0][display_id]' => 'block_1',
'field_view_test[0][arguments]' => 'page_test',
];
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->drupalPostForm('node/add/article_test', $edit, t('Save'));
$this->assertSession()->responseContains('Page 1');
$this->assertSession()->responseNotContains('Article 1');
$this->assertSession()->responseContains('Article 1');
$this->assertSession()->pageTextContains('This is jus ta test');
}
......
......@@ -2,16 +2,17 @@
namespace Drupal\Tests\viewfield\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\Entity\View;
/**
* Provide basic setup for all Viewfield functional tests.
*
* @group viewfield
*/
abstract class ViewfieldFunctionalTestBase extends BrowserTestBase {
abstract class ViewfieldFunctionalTestBase extends WebDriverTestBase {
/**
* Modules to enable.
......@@ -27,14 +28,14 @@ abstract class ViewfieldFunctionalTestBase extends BrowserTestBase {
];
/**
* The Entity View Display for the article node type.
* The Entity View Display for the article_test node type.
*
* @var \Drupal\Core\Entity\Entity\EntityViewDisplay
*/
protected $display;
/**
* The Entity Form Display for the article node type.
* The Entity Form Display for the article_test node type.
*
* @var \Drupal\Core\Entity\Entity\EntityFormDisplay
*/
......@@ -53,13 +54,13 @@ abstract class ViewfieldFunctionalTestBase extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(['type' => 'article']);
$this->drupalCreateContentType(['type' => 'page']);
$user = $this->drupalCreateUser(['create article content', 'edit own article content']);
$this->drupalCreateContentType(['type' => 'article_test']);
$this->drupalCreateContentType(['type' => 'page_test']);
$user = $this->drupalCreateUser(['create article_test content', 'edit own article_test content']);
$this->drupalLogin($user);
$entityTypeManager = $this->container->get('entity_type.manager');
FieldStorageConfig::create([
'field_name' => 'field_view',
'field_name' => 'field_view_test',
'entity_type' => 'node',
'type' => 'viewfield',
'settings' => [
......@@ -69,28 +70,32 @@ abstract class ViewfieldFunctionalTestBase extends BrowserTestBase {
'cardinality' => -1,
])->save();
FieldConfig::create([
'field_name' => 'field_view',
'field_name' => 'field_view_test',
'label' => 'Viewfield',
'description' => 'Viewfield description',
'entity_type' => 'node',
'bundle' => 'article',
'bundle' => 'article_test',
'settings' => [
'handler' => 'default',
'handler_settings' => [],
],
])->save();
$this->form = $entityTypeManager->getStorage('entity_form_display')
->load('node.article.default');
->load('node.article_test.default');
$this->display = $entityTypeManager->getStorage('entity_view_display')
->load('node.article.default');
->load('node.article_test.default');
// Create content for views to display.
for ($i = 1; $i <= 3; $i++) {
$this->createNode([
'title' => 'Page ' . $i,
'status' => TRUE,
'type' => 'page',
'type' => 'page_test',
]);
$this->createNode([
'title' => 'Article ' . $i,
'status' => TRUE,
'type' => 'article',
'type' => 'article_test',
]);
}
......@@ -105,7 +110,7 @@ abstract class ViewfieldFunctionalTestBase extends BrowserTestBase {
protected function createView($items_per_page = 3) {
View::create([
'label' => 'Content Test',
'id' => 'content',
'id' => 'content_test',
'base_table' => 'node_field_data',
'display' => [
'default' => [
......
......@@ -13,11 +13,11 @@ class ViewfieldWidgetTest extends ViewfieldFunctionalTestBase {
* Test select widget.
*/
public function testSelectWidget() {
$this->form->setComponent('field_view', [
$this->form->setComponent('field_view_test', [
'type' => 'viewfield_select',
])->save();
$this->display->setComponent('field_view', [
$this->display->setComponent('field_view_test', [
'type' => 'viewfield_title',
'weight' => 1,
])->save();
......@@ -25,27 +25,27 @@ class ViewfieldWidgetTest extends ViewfieldFunctionalTestBase {
$session = $this->assertSession();
// Confirm field label and description are rendered.
$this->drupalGet('node/add/article');
$session->fieldExists("field_view[0][target_id]");
$session->fieldExists("field_view[0][display_id]");
$session->fieldExists("field_view[0][arguments]");
$this->drupalGet('node/add/article_test');
$session->fieldExists("field_view_test[0][target_id]");
$session->fieldExists("field_view_test[0][display_id]");
$session->fieldExists("field_view_test[0][arguments]");
$session->responseContains('Viewfield');
$session->responseContains('Viewfield description');
// Test basic entry of color field.
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_view[0][target_id]' => "content",
'field_view[0][display_id]' => "block_1",
'field_view[0][arguments]' => "article",
'field_view_test[0][target_id]' => "content_test",
'field_view_test[0][display_id]' => "block_1",
'field_view_test[0][arguments]' => "article_test",
];
$this->drupalPostForm(NULL, $edit, t('Save'));
// Test response.
$session->responseContains('content');
$session->responseContains('content_test');
$session->responseContains('block_1');
$session->responseContains('article');
$session->responseContains('article_test');
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment