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') {
|
||||
// Add or remove the body field, as needed.
|
||||
$field_storage = FieldStorageConfig::loadByName('block_content', '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)) {
|
||||
$field = entity_create('field_config', array(
|
||||
'field_storage' => $field_storage,
|
||||
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
|
||||
'bundle' => $block_type_id,
|
||||
'label' => $label,
|
||||
'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\EntityTypeInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
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())));
|
||||
$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;
|
||||
|
||||
/**
|
||||
* {@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;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +27,14 @@ class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
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.
|
||||
$block_content = entity_create('block_content', array(
|
||||
'info' => 'Llama',
|
||||
|
|
|
@ -59,7 +59,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('!block %name has been created.', array(
|
||||
'!block' => 'Basic block',
|
||||
'!block' => 'basic',
|
||||
'%name' => $edit['info[0][value]']
|
||||
)), '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.
|
||||
$this->assertRaw(format_string('!block %name has been created.', array(
|
||||
'!block' => 'Basic block',
|
||||
'!block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
)), 'Basic block created.');
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use Drupal\simpletest\WebTestBase;
|
|||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
*/
|
||||
class BlockContentListTest extends WebTestBase {
|
||||
class BlockContentListTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
|
@ -47,6 +48,10 @@ abstract class BlockContentTestBase extends WebTestBase {
|
|||
*/
|
||||
protected function 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,19 @@ class BlockContentTranslationUITest extends ContentTranslationUITest {
|
|||
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().
|
||||
*/
|
||||
|
|
|
@ -56,6 +56,9 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
$block_type = entity_load('block_content_type', 'foo');
|
||||
$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.
|
||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||
$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.
|
||||
$this->createBlockContentType('other');
|
||||
|
||||
$field_definition = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other')['body'];
|
||||
$this->assertEqual($field_definition->getLabel(), 'Body', 'Body field was found.');
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$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.
|
||||
$this->drupalGet('block/add/basic');
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\config_translation\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
|
@ -387,6 +388,23 @@ class ConfigTranslationListUiTest extends WebTestBase {
|
|||
'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.
|
||||
$pages = array(
|
||||
array(
|
||||
|
|
|
@ -12,21 +12,5 @@ migrate.source.empty:
|
|||
type: string
|
||||
label: 'Provider'
|
||||
constants:
|
||||
type: mapping
|
||||
type: ignore
|
||||
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:
|
||||
required:
|
||||
- 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\block_content\Entity\BlockContent;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
|
||||
|
||||
|
@ -27,6 +28,13 @@ class MigrateBlockContentTest extends MigrateDrupalTestBase {
|
|||
*/
|
||||
protected function 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(
|
||||
'd6_filter_format' => array(
|
||||
array(array(2), array('full_html'))
|
||||
|
|
|
@ -61,6 +61,8 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
|
|||
'd6_aggregator_feed',
|
||||
'd6_aggregator_item',
|
||||
'd6_block',
|
||||
'd6_block_content_body_field',
|
||||
'd6_block_content_type',
|
||||
'd6_book',
|
||||
'd6_book_settings',
|
||||
'd6_cck_field_values:*',
|
||||
|
|
Loading…
Reference in New Issue