Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -28,3 +28,14 @@ function block_content_update_8001() {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
}
/**
* Generalizes the d6_block_content_type and d6_block_content_body_field
* migrations.
*/
function block_content_update_8002() {
// Removed in issue #2569605. The Migrate and Migrate Drupal modules are
// marked experimental and do not need to support the update path until they
// are stable.
// @see https://www.drupal.org/node/2569469
}

View file

@ -18,22 +18,22 @@ function block_content_help($route_name, RouteMatchInterface $route_match) {
$field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#';
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Custom Block module allows you to create custom <em>block types</em> and <em>content-containing blocks</em>, and provides a <a href="!block-library">Custom block library</a> listing all of them. Custom block types have fields; see the <a href="!field-help">Field module help</a> for more information. Once created, custom blocks can be placed in regions just like blocks provided by other modules; see the <a href="!blocks">Block module help page</a> for details. For more information, see <a href="!online-help">the online documentation for the Custom Block module</a>.', array('!block-library' => \Drupal::url('entity.block_content.collection'), '!block-content' => \Drupal::url('entity.block_content.collection'), '!field-help' => \Drupal::url('help.page', array('name' => 'field')), '!blocks' => \Drupal::url('help.page', array('name' => 'block')), '!online-help' => 'https://www.drupal.org/documentation/modules/block_content')) . '</p>';
$output .= '<p>' . t('The Custom Block module allows you to create custom <em>block types</em> and <em>content-containing blocks</em>, and provides a <a href=":block-library">Custom block library</a> listing all of them. Custom block types have fields; see the <a href=":field-help">Field module help</a> for more information. Once created, custom blocks can be placed in regions just like blocks provided by other modules; see the <a href=":blocks">Block module help page</a> for details. For more information, see the <a href=":online-help">online documentation for the Custom Block module</a>.', array(':block-library' => \Drupal::url('entity.block_content.collection'), ':block-content' => \Drupal::url('entity.block_content.collection'), ':field-help' => \Drupal::url('help.page', array('name' => 'field')), ':blocks' => \Drupal::url('help.page', array('name' => 'block')), ':online-help' => 'https://www.drupal.org/documentation/modules/block_content')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Creating and managing custom block types') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create and edit custom block types with fields and display settings, from the <a href="!types">Custom block types</a> page in the Custom block library. For more information about managing fields and display settings, see the <a href="!field-ui">Field UI module help</a>.', array('!types' => \Drupal::url('entity.block_content_type.collection'), '!field-ui' => $field_ui)) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create and edit custom block types with fields and display settings, from the <a href=":types">Custom block types</a> page in the Custom block library. For more information about managing fields and display settings, see the <a href=":field-ui">Field UI module help</a>.', array(':types' => \Drupal::url('entity.block_content_type.collection'), ':field-ui' => $field_ui)) . '</dd>';
$output .= '<dt>' . t('Creating custom blocks') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create, edit, and delete custom blocks of each custom block type you have defined, from the <a href="!block-library">Custom block library</a> page. Custom blocks are shown in the <em>Place blocks</em> list on the <a href="!blocks">Block layout page</a>; see the <a href="!block_help">Block module help</a> for more information about placing blocks.', array('!blocks' => \Drupal::url('block.admin_display'), '!block-library' => \Drupal::url('entity.block_content.collection'), '!block_help' => \Drupal::url('help.page', array('name' => 'block')))) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create, edit, and delete custom blocks of each custom block type you have defined, from the <a href=":block-library">Custom block library</a> page. Custom blocks are shown in the <em>Place blocks</em> list on the <a href=":blocks">Block layout page</a>; see the <a href=":block_help">Block module help</a> for more information about placing blocks.', array(':blocks' => \Drupal::url('block.admin_display'), ':block-library' => \Drupal::url('entity.block_content.collection'), ':block_help' => \Drupal::url('help.page', array('name' => 'block')))) . '</dd>';
$output .= '</dl>';
return $output;
case 'entity.block_content.collection':
$output = '<p>' . t('Blocks in the block library belong to <a href="!types">block types</a>, each with its own fields and display settings. After creating a block, place it in a region from the <a href="!blocks">Block layout page</a>.', array('!types' => \Drupal::url('entity.block_content_type.collection'), '!blocks' => \Drupal::url('block.admin_display'))) . '</p>';
$output = '<p>' . t('Blocks in the block library belong to <a href=":types">block types</a>, each with its own fields and display settings. After creating a block, place it in a region from the <a href=":blocks">Block layout page</a>.', array(':types' => \Drupal::url('entity.block_content_type.collection'), ':blocks' => \Drupal::url('block.admin_display'))) . '</p>';
return $output;
case 'entity.block_content_type.collection':
$output = '<p>' . t('Each block type has its own fields and display settings. Create blocks of each type on the <a href="!block-library">Block library page</a>.', array('!block-library' => \Drupal::url('entity.block_content.collection'))) . '</p>';
$output = '<p>' . t('Each block type has its own fields and display settings. Create blocks of each type on the <a href=":block-library">Block library page</a>.', array(':block-library' => \Drupal::url('entity.block_content.collection'))) . '</p>';
return $output;
}

View file

@ -76,7 +76,6 @@ entity.block_content_type.edit_form:
path: '/admin/structure/block/block-content/manage/{block_content_type}'
defaults:
_entity_form: 'block_content_type.edit'
_title: 'Edit'
requirements:
_entity_access: 'block_content_type.update'

View file

@ -1,8 +1,9 @@
id: block_content.full
label: Full
langcode: en
status: false
cache: true
targetEntityType: block_content
dependencies:
module:
- block_content
id: block_content.full
label: Full
targetEntityType: block_content
cache: true

View file

@ -15,3 +15,4 @@ cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: true
custom_storage: false

View file

@ -52,8 +52,8 @@ display:
id: 0
total_pages: null
tags:
previous: ' previous'
next: 'next '
previous: ' Previous'
next: 'Next '
expose:
items_per_page: false
items_per_page_label: 'Items per page'
@ -466,7 +466,10 @@ display:
- 'languages:language_content'
- 'languages:language_interface'
- url
cacheable: false
- url.query_args
- user.permissions
max-age: 0
tags: { }
page_1:
display_plugin: page
id: page_1
@ -488,4 +491,7 @@ display:
- 'languages:language_content'
- 'languages:language_interface'
- url
cacheable: false
- url.query_args
- user.permissions
max-age: 0
tags: { }

View file

@ -23,14 +23,13 @@
var $context = $(context);
$context.find('.block-content-form-revision-information').drupalSetSummary(function (context) {
var $revisionContext = $(context);
var revisionCheckbox = $revisionContext.find('.form-item-revision input');
var revisionCheckbox = $revisionContext.find('.js-form-item-revision input');
// Return 'New revision' if the 'Create new revision' checkbox is
// checked, or if the checkbox doesn't exist, but the revision log does.
// For users without the "Administer content" permission the checkbox
// won't appear, but the revision log will if the content type is set
// to auto-revision.
if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.form-item-revision-log textarea').length)) {
// Return 'New revision' if the 'Create new revision' checkbox is checked,
// or if the checkbox doesn't exist, but the revision log does. For users
// without the "Administer content" permission the checkbox won't appear,
// but the revision log will if the content type is set to auto-revision.
if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.js-form-item-revision-log textarea').length)) {
return Drupal.t('New revision');
}
@ -40,13 +39,13 @@
$context.find('fieldset.block-content-translation-options').drupalSetSummary(function (context) {
var $translationContext = $(context);
var translate;
var $checkbox = $translationContext.find('.form-item-translation-translate input');
var $checkbox = $translationContext.find('.js-form-item-translation-translate input');
if ($checkbox.size()) {
translate = $checkbox.is(':checked') ? Drupal.t('Needs to be updated') : Drupal.t('Does not need to be updated');
}
else {
$checkbox = $translationContext.find('.form-item-translation-retranslate input');
$checkbox = $translationContext.find('.js-form-item-translation-retranslate input');
translate = $checkbox.is(':checked') ? Drupal.t('Flag other translations as outdated') : Drupal.t('Do not flag other translations as outdated');
}

View file

@ -0,0 +1,32 @@
id: block_content_body_field
label: Block content body field configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: embedded_data
data_rows:
-
entity_type: block_content
bundle: basic
field_name: body
label: Body
display_summary: false
ids:
entity_type:
type: string
bundle:
type: string
field_name:
type: string
process:
entity_type: entity_type
bundle: bundle
field_name: field_name
label: label
'settings/display_summary': display_summary
destination:
plugin: entity:field_config
migration_dependencies:
required:
- block_content_type

View file

@ -0,0 +1,19 @@
id: block_content_type
label: Block content type
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: embedded_data
data_rows:
-
id: basic
label: Basic
ids:
id:
type: string
process:
id: id
label: label
destination:
plugin: entity:block_content_type

View file

@ -1,25 +0,0 @@
id: d6_block_content_body_field
label: Drupal 6 block content body field configuration
migration_tags:
- Drupal 6
source:
# We do an empty source and a proper destination to have an idmap for
# migration_dependencies.
plugin: md_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

View file

@ -1,16 +0,0 @@
id: d6_block_content_type
label: Drupal 6 block content type
migration_tags:
- Drupal 6
source:
# We do an empty source and a proper destination to have an idmap for
# migration_dependencies.
plugin: md_empty
constants:
id: basic
label: Basic
process:
id: 'constants/id'
label: 'constants/label'
destination:
plugin: entity:block_content_type

View file

@ -1,5 +1,5 @@
id: d6_custom_block
label: Drupal 6 custom blocks
label: Custom blocks
migration_tags:
- Drupal 6
source:
@ -21,4 +21,4 @@ destination:
migration_dependencies:
required:
- d6_filter_format
- d6_block_content_body_field
- block_content_body_field

View file

@ -0,0 +1,24 @@
id: d7_custom_block
label: Custom blocks
migration_tags:
- Drupal 7
source:
plugin: d7_block_custom
constants:
type: basic
process:
id: bid
type: 'constants/type'
info: info
'body/format':
plugin: migration
migration: d7_filter_format
source: format
'body/value': body
destination:
plugin: entity:block_content
no_stub: true
migration_dependencies:
required:
- d7_filter_format
- block_content_body_field

View file

@ -22,11 +22,11 @@ class BlockContentAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($operation === 'view') {
return AccessResult::allowed();
}
return parent::checkAccess($entity, $operation, $langcode, $account);
return parent::checkAccess($entity, $operation, $account);
}
}

View file

@ -7,7 +7,7 @@
namespace Drupal\block_content;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\language\Entity\ContentLanguageSettings;
@ -15,7 +15,7 @@ use Drupal\language\Entity\ContentLanguageSettings;
/**
* Base form for category edit forms.
*/
class BlockContentTypeForm extends EntityForm {
class BlockContentTypeForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
@ -26,6 +26,13 @@ class BlockContentTypeForm extends EntityForm {
/* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
$block_type = $this->entity;
if ($this->operation == 'add') {
$form['#title'] = $this->t('Add custom block type');
}
else {
$form['#title'] = $this->t('Edit %label custom block type', array('%label' => $block_type->label()));
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
@ -41,7 +48,6 @@ class BlockContentTypeForm extends EntityForm {
'exists' => '\Drupal\block_content\Entity\BlockContentType::load',
),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#disabled' => !$block_type->isNew(),
);
$form['description'] = array(
@ -55,7 +61,7 @@ class BlockContentTypeForm extends EntityForm {
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $block_type->shouldCreateNewRevision(),
'#description' => t('Create a new revision by default for this block type.')
'#description' => t('Create a new revision by default for this block type.'),
);
if ($this->moduleHandler->moduleExists('language')) {
@ -84,7 +90,7 @@ class BlockContentTypeForm extends EntityForm {
'#value' => t('Save'),
);
return $form;
return $this->protectBundleIdElement($form);
}
/**

View file

@ -38,8 +38,8 @@ class BlockContentViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) {
$build = parent::getBuildDefaults($entity, $view_mode, $langcode);
protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
$build = parent::getBuildDefaults($entity, $view_mode);
// The custom block will be rendered in the wrapped block template already
// and thus has no entity template itself.
unset($build['#theme']);
@ -49,8 +49,8 @@ class BlockContentViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
parent::alterBuild($build, $entity, $display, $view_mode);
// Add contextual links for this custom block.
if (!$entity->isNew()) {
$build['#contextual_links']['block_content'] = array(

View file

@ -86,8 +86,8 @@ class BlockContentController extends ControllerBase {
}
if (count($types) === 0) {
return array(
'#markup' => $this->t('You have not created any block types yet. Go to the <a href="!url">block type creation page</a> to add a new block type.', [
'!url' => Url::fromRoute('block_content.type_add')->toString(),
'#markup' => $this->t('You have not created any block types yet. Go to the <a href=":url">block type creation page</a> to add a new block type.', [
':url' => Url::fromRoute('block_content.type_add')->toString(),
]),
);
}

View file

@ -190,7 +190,7 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
'weight' => -5,
))
->setDisplayConfigurable('form', TRUE)
->addConstraint('BlockContentInfo', []);
->addConstraint('UniqueField', []);
$fields['type'] = BaseFieldDefinition::create('entity_reference')
@ -219,13 +219,6 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
return $fields;
}
/**
* {@inheritdoc}
*/
public function getChangedTime() {
return $this->get('changed')->value;
}
/**
* {@inheritdoc}
*/

View file

@ -115,7 +115,10 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
* Adds body and description fields to the block configuration form.
*/
public function blockForm($form, FormStateInterface $form_state) {
$options = $this->entityManager->getViewModeOptions('block_content');
$uuid = $this->getDerivativeId();
$block = $this->entityManager->loadEntityByUuid('block_content', $uuid);
$options = $this->entityManager->getViewModeOptionsByBundle('block_content', $block->bundle());
$form['view_mode'] = array(
'#type' => 'select',
'#options' => $options,
@ -156,9 +159,9 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
}
else {
return array(
'#markup' => $this->t('Block with uuid %uuid does not exist. <a href="!url">Add custom block</a>.', array(
'#markup' => $this->t('Block with uuid %uuid does not exist. <a href=":url">Add custom block</a>.', array(
'%uuid' => $this->getDerivativeId(),
'!url' => $this->urlGenerator->generate('block_content.add_page')
':url' => $this->urlGenerator->generate('block_content.add_page')
)),
'#access' => $this->account->hasPermission('administer blocks')
);

View file

@ -1,31 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Plugin\Validation\Constraint\BlockContentInfoConstraint.
*/
namespace Drupal\block_content\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Supports validating custom block names.
*
* @Constraint(
* id = "BlockContentInfo",
* label = @Translation("Custom block name", context = "Validation")
* )
*/
class BlockContentInfoConstraint extends Constraint {
public $message = 'A block with description %value already exists.';
/**
* {@inheritdoc}
*/
public function validatedBy() {
return '\Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldValueValidator';
}
}

View file

@ -0,0 +1,48 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Plugin\migrate\source\d7\BlockCustom.
*/
namespace Drupal\block_content\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 custom block source from database.
*
* @MigrateSource(
* id = "d7_block_custom"
* )
*/
class BlockCustom extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('block_custom', 'b')->fields('b');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'bid' => $this->t('The numeric identifier of the block/box'),
'body' => $this->t('The block/box content'),
'info' => $this->t('Admin title of the block/box.'),
'format' => $this->t('Input format of the custom block/box content.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['bid']['type'] = 'integer';
return $ids;
}
}

View file

@ -78,7 +78,7 @@ class ListingEmpty extends AreaPluginBase {
/** @var \Drupal\Core\Access\AccessResultInterface|\Drupal\Core\Cache\CacheableDependencyInterface $access_result */
$access_result = $this->accessManager->checkNamedRoute('block_content.add_page', array(), $this->currentUser, TRUE);
$element = array(
'#markup' => $this->t('Add a <a href="!url">custom block</a>.', array('!url' => Url::fromRoute('block_content.add_page')->toString())),
'#markup' => $this->t('Add a <a href=":url">custom block</a>.', array(':url' => Url::fromRoute('block_content.add_page')->toString())),
'#access' => $access_result->isAllowed(),
'#cache' => [
'contexts' => $access_result->getCacheContexts(),

View file

@ -21,12 +21,23 @@ class BlockContentCreationTest extends BlockContentTestBase {
/**
* Modules to enable.
*
* Enable dummy module that implements hook_block_insert() for exceptions.
* Enable dummy module that implements hook_block_insert() for exceptions and
* field_ui to edit display settings.
*
* @var array
*/
public static $modules = array('block_content_test', 'dblog', 'field_ui');
/**
* Permissions to grant admin user.
*
* @var array
*/
protected $permissions = array(
'administer blocks',
'administer block_content display'
);
/**
* Sets the test up.
*/
@ -48,8 +59,8 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
$this->assertRaw(format_string('!block %name has been created.', array(
'!block' => 'basic',
$this->assertRaw(format_string('@block %name has been created.', array(
'@block' => 'basic',
'%name' => $edit['info[0][value]']
)), 'Basic block created.');
@ -66,8 +77,8 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
$this->assertRaw(format_string('A block with description %name already exists.', array(
'%name' => $edit['info[0][value]']
$this->assertRaw(format_string('A custom block with block description %value already exists.', array(
'%value' => $edit['info[0][value]']
)));
$this->assertResponse(200);
}
@ -95,25 +106,46 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
$this->assertRaw(format_string('!block %name has been created.', array(
'!block' => 'basic',
$this->assertRaw(format_string('@block %name has been created.', array(
'@block' => 'basic',
'%name' => $edit['info[0][value]']
)), 'Basic block created.');
// Save our block permanently
$this->drupalPostForm(NULL, NULL, t('Save block'));
// Set test_view_mode as a custom display to be available on the list.
$this->drupalGet('admin/structure/block/block-content');
$this->drupalGet('admin/structure/block/block-content/types');
$this->clickLink(t('Manage display'));
$this->drupalGet('admin/structure/block/block-content/manage/basic/display');
$custom_view_mode = array(
'display_modes_custom[test_view_mode]' => 1,
);
$this->drupalPostForm(NULL, $custom_view_mode, t('Save'));
// Go to the configure page and change the view mode.
$this->drupalGet('admin/structure/block/manage/testblock');
// Test the available view mode options.
$this->assertOption('edit-settings-view-mode', 'default', 'The default view mode is available.');
$this->assertOption('edit-settings-view-mode', 'test_view_mode', 'The test view mode is available.');
$view_mode['settings[view_mode]'] = 'test_view_mode';
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
// Check that the view mode setting is shown because more than one exists.
$this->drupalGet('admin/structure/block/manage/testblock');
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
// Change the view mode.
$view_mode['settings[view_mode]'] = 'test_view_mode';
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
// Go to the configure page and verify that the new view mode is correct.
// Go to the configure page and verify the view mode has changed.
$this->drupalGet('admin/structure/block/manage/testblock');
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]/@value', 'test_view_mode', 'View mode changed to Test View Mode');
// Test the available view mode options.
$this->assertOption('edit-settings-view-mode', 'default', 'The default view mode is available.');
// Check that the block exists in the database.
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
$block = reset($blocks);
@ -124,8 +156,8 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
$this->assertRaw(format_string('A block with description %name already exists.', array(
'%name' => $edit['info[0][value]']
$this->assertRaw(format_string('A custom block with block description %value already exists.', array(
'%value' => $edit['info[0][value]']
)));
$this->assertResponse(200);
}
@ -144,8 +176,8 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->drupalPostForm('block/add', $edit, t('Save'));
// 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',
$this->assertRaw(format_string('@block %name has been created.', array(
'@block' => 'basic',
'%name' => $edit['info[0][value]'],
)), 'Basic block created.');

View file

@ -46,7 +46,7 @@ class BlockContentListTest extends BlockContentTestBase {
// Test the contents of each th cell.
$expected_items = array(t('Block description'), t('Operations'));
foreach ($elements as $key => $element) {
$this->assertIdentical((string) $element[0], $expected_items[$key]);
$this->assertEqual($element[0], $expected_items[$key]);
}
$label = 'Antelope';

View file

@ -42,7 +42,7 @@ class BlockContentListViewsTest extends BlockContentTestBase {
$this->assertEqual(count($elements), 4, 'Correct number of table header cells found.');
// Test the contents of each th cell.
$expected_items = [t('Block description'), t('Block type'), t('Updated'), t('Operations')];
$expected_items = ['Block description', 'Block type', 'Updated', 'Operations'];
foreach ($elements as $key => $element) {
if ($element->xpath('a')) {
$this->assertIdentical(trim((string) $element->xpath('a')[0]), $expected_items[$key]);

View file

@ -69,8 +69,8 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
// Confirm the correct revision text appears.
$loaded = entity_revision_load('block_content', $revision_id);
// Verify revision log is the same.
$this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision !revision', array(
'!revision' => $loaded->getRevisionId(),
$this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
'@revision' => $loaded->getRevisionId(),
)));
}

View file

@ -71,17 +71,20 @@ abstract class BlockContentTestBase extends WebTestBase {
* Defaults to FALSE.
* @param string $bundle
* (optional) Bundle name. Defaults to 'basic'.
* @param bool $save
* (optional) Whether to save the block. Defaults to TRUE.
*
* @return \Drupal\block_content\Entity\BlockContent
* Created custom block.
*/
protected function createBlockContent($title = FALSE, $bundle = 'basic') {
protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
$title = ($title ? : $this->randomMachineName());
if ($block_content = entity_create('block_content', array(
$block_content = entity_create('block_content', array(
'info' => $title,
'type' => $bundle,
'langcode' => 'en'
))) {
));
if ($block_content && $save === TRUE) {
$block_content->save();
}
return $block_content;

View file

@ -35,6 +35,7 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
*/
protected $defaultCacheContexts = [
'languages:language_interface',
'session',
'theme',
'url.path',
'url.query_args',
@ -50,6 +51,8 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
$this->bundle = 'basic';
$this->testLanguageSelector = FALSE;
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
}
/**

View file

@ -42,6 +42,12 @@ class BlockContentTypeTest extends BlockContentTestBase {
*/
protected $autoCreateBasicBlockType = FALSE;
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
}
/**
* Tests creating a block type programmatically and via a form.
*/
@ -52,35 +58,39 @@ class BlockContentTypeTest extends BlockContentTestBase {
// Test the page with no block-types.
$this->drupalGet('block/add');
$this->assertResponse(200);
$this->assertRaw(t('You have not created any block types yet. Go to the <a href="!url">block type creation page</a> to add a new block type.', [
'!url' => Url::fromRoute('block_content.type_add')->toString(),
]));
// Now create an initial block-type.
$this->createBlockContentType('basic', TRUE);
// Create a block type programmatically.
$type = $this->createBlockContentType('other');
$block_type = BlockContentType::load('other');
$this->assertTrue($block_type, 'The new block type has been created.');
$this->drupalGet('block/add/' . $type->id());
$this->assertResponse(200, 'The new block type can be accessed at block/add.');
$this->assertText('You have not created any block types yet');
$this->clickLink('block type creation page');
// Create a block type via the user interface.
$edit = array(
'id' => 'foo',
'label' => 'title for foo',
);
$this->drupalPostForm('admin/structure/block/block-content/types/add', $edit, t('Save'));
$this->drupalPostForm(NULL, $edit, t('Save'));
$block_type = BlockContentType::load('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.');
$this->assertTrue(isset($field_definitions['body']), 'Body field 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);
// Create block types programmatically.
$this->createBlockContentType('basic', TRUE);
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'basic');
$this->assertTrue(isset($field_definitions['body']), "Body field for 'basic' block type created when using the testing API to create block content types.");
$this->createBlockContentType('other');
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
$this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types.");
$block_type = BlockContentType::load('other');
$this->assertTrue($block_type, 'The new block type has been created.');
$this->drupalGet('block/add/' . $block_type->id());
$this->assertResponse(200);
}
/**
@ -106,7 +116,9 @@ class BlockContentTypeTest extends BlockContentTestBase {
$edit = array(
'label' => 'Bar',
);
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', $edit, t('Save'));
$this->drupalGet('admin/structure/block/block-content/manage/basic');
$this->assertTitle(format_string('Edit @type custom block type | Drupal', ['@type' => 'basic']));
$this->drupalPostForm(NULL, $edit, t('Save'));
\Drupal::entityManager()->clearCachedFieldDefinitions();
$this->drupalGet('block/add');

View file

@ -37,7 +37,7 @@ class BlockContentValidationTest extends BlockContentTestBase {
// Make sure the violation is on the info property
$this->assertEqual($violations[0]->getPropertyPath(), 'info');
// Make sure the message is correct.
$this->assertEqual($violations[0]->getMessage(), format_string('A block with description %value already exists.', [
$this->assertEqual($violations[0]->getMessage(), format_string('A custom block with block description %value already exists.', [
'%value' => $block->label(),
]));
}

View file

@ -0,0 +1,58 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Migrate\MigrateBlockContentBodyFieldTest.
*/
namespace Drupal\block_content\Tests\Migrate;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Attaches a body field to the custom block type.
*
* @group block_content
*/
class MigrateBlockContentBodyFieldTest extends MigrateDrupal7TestBase {
static $modules = array('block', 'block_content', 'filter', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['block_content']);
$this->installEntitySchema('block_content');
$this->executeMigrations([
'block_content_type',
'block_content_body_field',
]);
}
/**
* Tests the block content body field migration.
*/
public function testBlockContentBodyFieldMigration() {
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = FieldStorageConfig::load('block_content.body');
$this->assertTrue($storage instanceof FieldStorageConfigInterface);
$this->assertIdentical('block_content', $storage->getTargetEntityTypeId());
$this->assertIdentical(['basic'], array_values($storage->getBundles()));
$this->assertIdentical('body', $storage->getName());
/** @var \Drupal\field\FieldConfigInterface $field */
$field = FieldConfig::load('block_content.basic.body');
$this->assertTrue($field instanceof FieldConfigInterface);
$this->assertIdentical('block_content', $field->getTargetEntityTypeId());
$this->assertIdentical('basic', $field->getTargetBundle());
$this->assertIdentical('body', $field->getName());
$this->assertIdentical('Body', $field->getLabel());
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Migrate\MigrateBlockContentTypeTest.
*/
namespace Drupal\block_content\Tests\Migrate;
use Drupal\block_content\BlockContentTypeInterface;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests migration of the basic block content type.
*
* @group block_content
*/
class MigrateBlockContentTypeTest extends MigrateDrupal7TestBase {
static $modules = array('block', 'block_content', 'filter', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['block_content']);
$this->installEntitySchema('block_content');
$this->executeMigration('block_content_type');
}
/**
* Tests the block content type migration.
*/
public function testBlockContentTypeMigration() {
/** @var \Drupal\block_content\BlockContentTypeInterface $entity */
$entity = BlockContentType::load('basic');
$this->assertTrue($entity instanceof BlockContentTypeInterface);
$this->assertIdentical('Basic', $entity->label());
}
}

View file

@ -17,25 +17,25 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
*/
class MigrateBlockContentTest extends MigrateDrupal6TestBase {
static $modules = array('block', 'block_content', 'filter', 'text');
/**
* {@inheritdoc}
*/
public static $modules = ['block', 'block_content'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(array('block_content'));
$this->installConfig(['block_content']);
$this->installEntitySchema('block_content');
$this->executeMigration('d6_block_content_type');
$this->executeMigration('d6_block_content_body_field');
$this->prepareMigrations(array(
'd6_filter_format' => array(
array(array(2), array('full_html'))
)
));
$this->executeMigration('d6_custom_block');
$this->executeMigrations([
'd6_filter_format',
'block_content_type',
'block_content_body_field',
'd6_custom_block',
]);
}
/**

View file

@ -0,0 +1,57 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Migrate\d7\MigrateCustomBlockTest.
*/
namespace Drupal\block_content\Tests\Migrate\d7;
use Drupal\block_content\BlockContentInterface;
use Drupal\block_content\Entity\BlockContent;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests migration of custom blocks.
*
* @group block_content
*/
class MigrateCustomBlockTest extends MigrateDrupal7TestBase {
public static $modules = array(
'block_content',
'filter',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->installEntitySchema('block_content');
$this->executeMigrations([
'd7_filter_format',
'block_content_type',
'block_content_body_field',
'd7_custom_block',
]);
}
/**
* Tests migration of custom blocks from Drupal 7 to Drupal 8.
*/
public function testCustomBlockMigration() {
$block = BlockContent::load(1);
$this->assertTrue($block instanceof BlockContentInterface);
/** @var \Drupal\block_content\BlockContentInterface $block */
$this->assertIdentical('Limerick', $block->label());
$expected_body = "A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
$this->assertIdentical($expected_body, $block->body->value);
$this->assertIdentical('filtered_html', $block->body->format);
}
}

View file

@ -17,6 +17,12 @@ use Drupal\Component\Utility\Unicode;
*/
class PageEditTest extends BlockContentTestBase {
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
}
/**
* Checks block edit functionality.
*/
@ -64,7 +70,7 @@ class PageEditTest extends BlockContentTestBase {
// Test deleting the block.
$this->drupalGet("block/" . $revised_block->id());
$this->clickLink(t('Delete'));
$this->assertText(format_string('Are you sure you want to delete the custom block !label?', array('!label' => $revised_block->label())));
$this->assertText(format_string('Are you sure you want to delete the custom block @label?', array('@label' => $revised_block->label())));
}
}

View file

@ -58,10 +58,10 @@ display:
offset: false
offset_label: Offset
tags:
previous: ' previous'
next: 'next '
first: first'
last: 'last »'
previous: ' Previous'
next: 'Next '
first: First'
last: 'Last »'
quantity: 9
style:
type: default

View file

@ -16,21 +16,15 @@ use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
*/
class BoxTest extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\block_content\Plugin\migrate\source\d6\Box';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'test',
'source' => array(
'plugin' => 'd6_boxes',
),
);
// We need to set up the database contents; it's easier to do that below.
// These are sample result queries.
protected $expectedResults = array(
array(
'bid' => 1,

View file

@ -0,0 +1,45 @@
<?php
/**
* @file
* Contains \Drupal\Tests\block_content\Unit\Plugin\migrate\source\d7\BlockCustomTest.
*/
namespace Drupal\Tests\block_content\Unit\Plugin\migrate\source\d7;
use Drupal\block_content\Plugin\migrate\source\d7\BlockCustom;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* @coversDefaultClass \Drupal\block_content\Plugin\migrate\source\d7\BlockCustom
* @group block_content
*/
class BlockCustomTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = BlockCustom::class;
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd7_block_custom',
),
);
protected $expectedResults = array(
array(
'bid' => '1',
'body' => "I don't feel creative enough to write anything clever here.",
'info' => 'Meh',
'format' => 'filtered_html',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['block_custom'] = $this->expectedResults;
parent::setUp();
}
}