Issue #2374125 by alexpott: Create a persistent block_content body field storage
parent
7822393c30
commit
b313cc6ae4
|
@ -76,19 +76,10 @@ function block_content_entity_type_alter(array &$entity_types) {
|
||||||
*/
|
*/
|
||||||
function block_content_add_body_field($block_type_id, $label = 'Body') {
|
function block_content_add_body_field($block_type_id, $label = 'Body') {
|
||||||
// Add or remove the body field, as needed.
|
// Add or remove the body field, as needed.
|
||||||
$field_storage = FieldStorageConfig::loadByName('block_content', 'body');
|
|
||||||
$field = FieldConfig::loadByName('block_content', $block_type_id, 'body');
|
$field = FieldConfig::loadByName('block_content', $block_type_id, 'body');
|
||||||
if (empty($field_storage)) {
|
|
||||||
$field_storage = entity_create('field_storage_config', array(
|
|
||||||
'field_name' => 'body',
|
|
||||||
'entity_type' => 'block_content',
|
|
||||||
'type' => 'text_with_summary',
|
|
||||||
));
|
|
||||||
$field_storage->save();
|
|
||||||
}
|
|
||||||
if (empty($field)) {
|
if (empty($field)) {
|
||||||
$field = entity_create('field_config', array(
|
$field = entity_create('field_config', array(
|
||||||
'field_storage' => $field_storage,
|
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
|
||||||
'bundle' => $block_type_id,
|
'bundle' => $block_type_id,
|
||||||
'label' => $label,
|
'label' => $label,
|
||||||
'settings' => array('display_summary' => FALSE),
|
'settings' => array('display_summary' => FALSE),
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
langcode: en
|
||||||
|
status: true
|
||||||
|
dependencies:
|
||||||
|
module:
|
||||||
|
- block_content
|
||||||
|
- text
|
||||||
|
id: block_content.body
|
||||||
|
field_name: body
|
||||||
|
entity_type: block_content
|
||||||
|
type: text_with_summary
|
||||||
|
settings: { }
|
||||||
|
module: text
|
||||||
|
locked: false
|
||||||
|
cardinality: 1
|
||||||
|
translatable: true
|
||||||
|
indexes: { }
|
||||||
|
persist_with_no_fields: true
|
|
@ -10,6 +10,8 @@ namespace Drupal\block_content;
|
||||||
use Drupal\Core\Entity\EntityForm;
|
use Drupal\Core\Entity\EntityForm;
|
||||||
use Drupal\Core\Entity\EntityTypeInterface;
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\field\Entity\FieldConfig;
|
||||||
|
use Drupal\field\Entity\FieldStorageConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base form for category edit forms.
|
* Base form for category edit forms.
|
||||||
|
@ -99,6 +101,7 @@ class BlockContentTypeForm extends EntityForm {
|
||||||
$logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link));
|
$logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
block_content_add_body_field($block_type->id());
|
||||||
drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label())));
|
drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label())));
|
||||||
$logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link));
|
$logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link));
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,15 +70,4 @@ class BlockContentType extends ConfigEntityBundleBase implements BlockContentTyp
|
||||||
*/
|
*/
|
||||||
public $description;
|
public $description;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
|
|
||||||
parent::postSave($storage, $update);
|
|
||||||
|
|
||||||
if (!$update && !$this->isSyncing()) {
|
|
||||||
block_content_add_body_field($this->id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\block_content\Tests;
|
namespace Drupal\block_content\Tests;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
use Drupal\field\Entity\FieldStorageConfig;
|
||||||
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
|
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +27,14 @@ class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function createEntity() {
|
protected function createEntity() {
|
||||||
|
$block_content_type = entity_create('block_content_type', array(
|
||||||
|
'id' => 'basic',
|
||||||
|
'label' => 'basic',
|
||||||
|
'revision' => FALSE
|
||||||
|
));
|
||||||
|
$block_content_type->save();
|
||||||
|
block_content_add_body_field($block_content_type->id());
|
||||||
|
|
||||||
// Create a "Llama" custom block.
|
// Create a "Llama" custom block.
|
||||||
$block_content = entity_create('block_content', array(
|
$block_content = entity_create('block_content', array(
|
||||||
'info' => 'Llama',
|
'info' => 'Llama',
|
||||||
|
|
|
@ -59,7 +59,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
||||||
|
|
||||||
// Check that the Basic block has been created.
|
// Check that the Basic block has been created.
|
||||||
$this->assertRaw(format_string('!block %name has been created.', array(
|
$this->assertRaw(format_string('!block %name has been created.', array(
|
||||||
'!block' => 'Basic block',
|
'!block' => 'basic',
|
||||||
'%name' => $edit['info[0][value]']
|
'%name' => $edit['info[0][value]']
|
||||||
)), 'Basic block created.');
|
)), 'Basic block created.');
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
||||||
|
|
||||||
// Check that the block has been created and that it is a basic block.
|
// Check that the block has been created and that it is a basic block.
|
||||||
$this->assertRaw(format_string('!block %name has been created.', array(
|
$this->assertRaw(format_string('!block %name has been created.', array(
|
||||||
'!block' => 'Basic block',
|
'!block' => 'basic',
|
||||||
'%name' => $edit['info[0][value]'],
|
'%name' => $edit['info[0][value]'],
|
||||||
)), 'Basic block created.');
|
)), 'Basic block created.');
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use Drupal\simpletest\WebTestBase;
|
||||||
* @group block_content
|
* @group block_content
|
||||||
* @see \Drupal\block\BlockContentListBuilder
|
* @see \Drupal\block\BlockContentListBuilder
|
||||||
*/
|
*/
|
||||||
class BlockContentListTest extends WebTestBase {
|
class BlockContentListTest extends BlockContentTestBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules to enable.
|
* Modules to enable.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\block_content\Tests;
|
namespace Drupal\block_content\Tests;
|
||||||
|
|
||||||
|
use Drupal\field\Entity\FieldStorageConfig;
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,6 +48,10 @@ abstract class BlockContentTestBase extends WebTestBase {
|
||||||
*/
|
*/
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
// Ensure the basic bundle exists. This is provided by the standard profile.
|
||||||
|
$block_content_type = $this->createBlockContentType('basic');
|
||||||
|
block_content_add_body_field($block_content_type->id());
|
||||||
|
|
||||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,19 @@ class BlockContentTranslationUITest extends ContentTranslationUITest {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setupBundle() {
|
||||||
|
// Create the basic bundle since it is provided by standard.
|
||||||
|
$bundle = entity_create('block_content_type', array(
|
||||||
|
'id' => $this->bundle,
|
||||||
|
'label' => $this->bundle,
|
||||||
|
'revision' => FALSE
|
||||||
|
));
|
||||||
|
$bundle->save();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getTranslatorPermission().
|
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getTranslatorPermission().
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,6 +56,9 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
||||||
$block_type = entity_load('block_content_type', 'foo');
|
$block_type = entity_load('block_content_type', 'foo');
|
||||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||||
|
|
||||||
|
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo');
|
||||||
|
$this->assertTrue(isset($field_definitions['body']), 'Body field was created when using the UI to create block content types.');
|
||||||
|
|
||||||
// Check that the block type was created in site default language.
|
// Check that the block type was created in site default language.
|
||||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||||
$this->assertEqual($block_type->language()->getId(), $default_langcode);
|
$this->assertEqual($block_type->language()->getId(), $default_langcode);
|
||||||
|
@ -69,8 +72,8 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
||||||
// We need two block types to prevent /block/add redirecting.
|
// We need two block types to prevent /block/add redirecting.
|
||||||
$this->createBlockContentType('other');
|
$this->createBlockContentType('other');
|
||||||
|
|
||||||
$field_definition = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other')['body'];
|
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||||
$this->assertEqual($field_definition->getLabel(), 'Body', 'Body field was found.');
|
$this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
|
||||||
|
|
||||||
// Verify that title and body fields are displayed.
|
// Verify that title and body fields are displayed.
|
||||||
$this->drupalGet('block/add/basic');
|
$this->drupalGet('block/add/basic');
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\config_translation\Tests;
|
namespace Drupal\config_translation\Tests;
|
||||||
|
|
||||||
use Drupal\Component\Utility\Unicode;
|
use Drupal\Component\Utility\Unicode;
|
||||||
|
use Drupal\field\Entity\FieldStorageConfig;
|
||||||
use Drupal\language\Entity\ConfigurableLanguage;
|
use Drupal\language\Entity\ConfigurableLanguage;
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
|
@ -387,6 +388,23 @@ class ConfigTranslationListUiTest extends WebTestBase {
|
||||||
'name' => $this->randomMachineName(),
|
'name' => $this->randomMachineName(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Create a block content type.
|
||||||
|
$block_content_type = entity_create('block_content_type', array(
|
||||||
|
'id' => 'basic',
|
||||||
|
'label' => 'Basic',
|
||||||
|
'revision' => FALSE
|
||||||
|
));
|
||||||
|
$block_content_type->save();
|
||||||
|
$field = entity_create('field_config', array(
|
||||||
|
// The field storage is guaranteed to exist because it is supplied by the
|
||||||
|
// block_content module.
|
||||||
|
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
|
||||||
|
'bundle' => $block_content_type->id(),
|
||||||
|
'label' => 'Body',
|
||||||
|
'settings' => array('display_summary' => FALSE),
|
||||||
|
));
|
||||||
|
$field->save();
|
||||||
|
|
||||||
// Look at a few fields on a few entity types.
|
// Look at a few fields on a few entity types.
|
||||||
$pages = array(
|
$pages = array(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -12,21 +12,5 @@ migrate.source.empty:
|
||||||
type: string
|
type: string
|
||||||
label: 'Provider'
|
label: 'Provider'
|
||||||
constants:
|
constants:
|
||||||
type: mapping
|
type: ignore
|
||||||
label: 'Constants'
|
label: 'Constants'
|
||||||
mapping:
|
|
||||||
entity_type:
|
|
||||||
type: string
|
|
||||||
label: 'Entity type'
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
label: 'Type'
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
label: 'Name'
|
|
||||||
cardinality:
|
|
||||||
type: integer
|
|
||||||
label: 'Cardinality'
|
|
||||||
display_field:
|
|
||||||
type: boolean
|
|
||||||
label: 'Display field'
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
id: d6_block_content_body_field
|
||||||
|
label: Drupal 6 block content body field configuration
|
||||||
|
migration_groups:
|
||||||
|
- Drupal 6
|
||||||
|
source:
|
||||||
|
# We do an empty source and a proper destination to have an idmap for
|
||||||
|
# migration_dependencies.
|
||||||
|
plugin: empty
|
||||||
|
constants:
|
||||||
|
entity_type: block_content
|
||||||
|
bundle: basic
|
||||||
|
name: body
|
||||||
|
label: Body
|
||||||
|
display_summary: false
|
||||||
|
process:
|
||||||
|
entity_type: 'constants/entity_type'
|
||||||
|
bundle: 'constants/bundle'
|
||||||
|
field_name: 'constants/name'
|
||||||
|
label: 'constants/label'
|
||||||
|
'settings/display_summary': 'constants/display_summary'
|
||||||
|
destination:
|
||||||
|
plugin: entity:field_config
|
||||||
|
migration_dependencies:
|
||||||
|
required:
|
||||||
|
- d6_block_content_type
|
|
@ -0,0 +1,16 @@
|
||||||
|
id: d6_block_content_type
|
||||||
|
label: Drupal 6 block content type
|
||||||
|
migration_groups:
|
||||||
|
- Drupal 6
|
||||||
|
source:
|
||||||
|
# We do an empty source and a proper destination to have an idmap for
|
||||||
|
# migration_dependencies.
|
||||||
|
plugin: empty
|
||||||
|
constants:
|
||||||
|
id: basic
|
||||||
|
label: Basic
|
||||||
|
process:
|
||||||
|
id: 'constants/id'
|
||||||
|
label: 'constants/label'
|
||||||
|
destination:
|
||||||
|
plugin: entity:block_content_type
|
|
@ -20,3 +20,4 @@ destination:
|
||||||
migration_dependencies:
|
migration_dependencies:
|
||||||
required:
|
required:
|
||||||
- d6_filter_format
|
- d6_filter_format
|
||||||
|
- d6_block_content_body_field
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\migrate_drupal\Tests\d6;
|
||||||
use Drupal\Core\Language\Language;
|
use Drupal\Core\Language\Language;
|
||||||
use Drupal\block_content\Entity\BlockContent;
|
use Drupal\block_content\Entity\BlockContent;
|
||||||
use Drupal\Core\Language\LanguageInterface;
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
|
use Drupal\field\Entity\FieldStorageConfig;
|
||||||
use Drupal\migrate\MigrateExecutable;
|
use Drupal\migrate\MigrateExecutable;
|
||||||
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
|
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
|
||||||
|
|
||||||
|
@ -27,6 +28,13 @@ class MigrateBlockContentTest extends MigrateDrupalTestBase {
|
||||||
*/
|
*/
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
$migration = entity_load('migration', 'd6_block_content_type');
|
||||||
|
$executable = new MigrateExecutable($migration, $this);
|
||||||
|
$executable->import();
|
||||||
|
$migration = entity_load('migration', 'd6_block_content_body_field');
|
||||||
|
$executable = new MigrateExecutable($migration, $this);
|
||||||
|
$executable->import();
|
||||||
|
|
||||||
$this->prepareMigrations(array(
|
$this->prepareMigrations(array(
|
||||||
'd6_filter_format' => array(
|
'd6_filter_format' => array(
|
||||||
array(array(2), array('full_html'))
|
array(array(2), array('full_html'))
|
||||||
|
|
|
@ -61,6 +61,8 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
|
||||||
'd6_aggregator_feed',
|
'd6_aggregator_feed',
|
||||||
'd6_aggregator_item',
|
'd6_aggregator_item',
|
||||||
'd6_block',
|
'd6_block',
|
||||||
|
'd6_block_content_body_field',
|
||||||
|
'd6_block_content_type',
|
||||||
'd6_book',
|
'd6_book',
|
||||||
'd6_book_settings',
|
'd6_book_settings',
|
||||||
'd6_cck_field_values:*',
|
'd6_cck_field_values:*',
|
||||||
|
|
Loading…
Reference in New Issue