Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -61,3 +61,14 @@ function block_content_update_8003() {
|
|||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the block_content entity type to specify its revision data table.
|
||||
*/
|
||||
function block_content_update_8300() {
|
||||
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $definition_update_manager->getEntityType('block_content');
|
||||
$entity_type->set('revision_data_table', 'block_content_field_revision');
|
||||
$definition_update_manager->updateEntityType($entity_type);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# Deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
|
||||
# This is just for BC and not used anymore. See https://www.drupal.org/node/2669802
|
||||
drupal.block_content:
|
||||
version: VERSION
|
||||
js:
|
||||
js/block_content.js: {}
|
||||
js: {}
|
||||
dependencies:
|
||||
- core/jquery
|
||||
- core/drupal
|
||||
- core/drupal.form
|
||||
- core/drupal.entity-form
|
||||
|
|
|
@ -2,9 +2,3 @@ block_content.block_edit:
|
|||
title: 'Edit'
|
||||
group: block_content
|
||||
route_name: 'entity.block_content.canonical'
|
||||
|
||||
block_content.block_delete:
|
||||
title: 'Delete'
|
||||
group: block_content
|
||||
route_name: 'entity.block_content.delete_form'
|
||||
weight: 1
|
||||
|
|
|
@ -15,25 +15,25 @@ use Drupal\field\Entity\FieldStorageConfig;
|
|||
function block_content_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.block_content':
|
||||
$field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#';
|
||||
$field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#';
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Custom Block module allows you to create and manage custom <em>block types</em> and <em>content-containing blocks</em> from the <a href = ":block-library" >Custom block library<a/> page. 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</a> page 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 .= '<p>' . t('The Custom Block module allows you to create and manage custom <em>block types</em> and <em>content-containing blocks</em> from the <a href = ":block-library" >Custom block library<a/> page. 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</a> page for details. For more information, see the <a href=":online-help">online documentation for the Custom Block module</a>.', [':block-library' => \Drupal::url('entity.block_content.collection'), ':block-content' => \Drupal::url('entity.block_content.collection'), ':field-help' => \Drupal::url('help.page', ['name' => 'field']), ':blocks' => \Drupal::url('help.page', ['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">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">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>.', [':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 defined custom block type, from the <a href=":block-library">Blocks</a> page in the Custom block library. After creating a block, place it in a region from the <a href=":blocks">Block layout</a> page; 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 defined custom block type, from the <a href=":block-library">Blocks</a> page in the Custom block library. After creating a block, place it in a region from the <a href=":blocks">Block layout</a> page; see the <a href=":block_help">Block module help</a> for more information about placing blocks.', [':blocks' => \Drupal::url('block.admin_display'), ':block-library' => \Drupal::url('entity.block_content.collection'), ':block_help' => \Drupal::url('help.page', ['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">Custom 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</a> page.', 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">Custom 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</a> page.', [':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">Blocks</a> page in the custom block library.', 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">Blocks</a> page in the custom block library.', [':block-library' => \Drupal::url('entity.block_content.collection')]) . '</p>';
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ function block_content_help($route_name, RouteMatchInterface $route_match) {
|
|||
* Implements hook_theme().
|
||||
*/
|
||||
function block_content_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'block_content_add_list' => array(
|
||||
'variables' => array('content' => NULL),
|
||||
return [
|
||||
'block_content_add_list' => [
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'block_content.pages.inc',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,23 +83,23 @@ function block_content_add_body_field($block_type_id, $label = 'Body') {
|
|||
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
|
||||
'bundle' => $block_type_id,
|
||||
'label' => $label,
|
||||
'settings' => array('display_summary' => FALSE),
|
||||
'settings' => ['display_summary' => FALSE],
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Assign widget settings for the 'default' form mode.
|
||||
entity_get_form_display('block_content', $block_type_id, 'default')
|
||||
->setComponent('body', array(
|
||||
->setComponent('body', [
|
||||
'type' => 'text_textarea_with_summary',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Assign display settings for 'default' view mode.
|
||||
entity_get_display('block_content', $block_type_id, 'default')
|
||||
->setComponent('body', array(
|
||||
->setComponent('body', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,18 +19,18 @@ use Drupal\Core\Url;
|
|||
* @see block_content_add_page()
|
||||
*/
|
||||
function template_preprocess_block_content_add_list(&$variables) {
|
||||
$variables['types'] = array();
|
||||
$variables['types'] = [];
|
||||
$query = \Drupal::request()->query->all();
|
||||
foreach ($variables['content'] as $type) {
|
||||
$variables['types'][$type->id()] = array(
|
||||
'link' => \Drupal::l($type->label(), new Url('block_content.add_form', array('block_content_type' => $type->id()), array('query' => $query))),
|
||||
'description' => array(
|
||||
$variables['types'][$type->id()] = [
|
||||
'link' => \Drupal::l($type->label(), new Url('block_content.add_form', ['block_content_type' => $type->id()], ['query' => $query])),
|
||||
'description' => [
|
||||
'#markup' => $type->getDescription(),
|
||||
),
|
||||
],
|
||||
'title' => $type->label(),
|
||||
'localized_options' => array(
|
||||
'localized_options' => [
|
||||
'query' => $query,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/**
|
||||
* @file
|
||||
* Defines Javascript behaviors for the block_content module.
|
||||
*/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Sets summaries about revision and translation of block content.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches summary behaviour block content form tabs.
|
||||
*
|
||||
* Specifically, it updates summaries to the revision information and the
|
||||
* translation options.
|
||||
*/
|
||||
Drupal.behaviors.blockContentDetailsSummaries = {
|
||||
attach: function (context) {
|
||||
var $context = $(context);
|
||||
$context.find('.block-content-form-revision-information').drupalSetSummary(function (context) {
|
||||
var $revisionContext = $(context);
|
||||
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('.js-form-item-revision-log textarea').length)) {
|
||||
return Drupal.t('New revision');
|
||||
}
|
||||
|
||||
return Drupal.t('No revision');
|
||||
});
|
||||
|
||||
$context.find('fieldset.block-content-translation-options').drupalSetSummary(function (context) {
|
||||
var $translationContext = $(context);
|
||||
var translate;
|
||||
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('.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');
|
||||
}
|
||||
|
||||
return translate;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
|
@ -4,38 +4,13 @@ namespace Drupal\block_content;
|
|||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Form handler for the custom block edit forms.
|
||||
*/
|
||||
class BlockContentForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* The custom block storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $blockContentStorage;
|
||||
|
||||
/**
|
||||
* The custom block type storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $blockContentTypeStorage;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The block content entity.
|
||||
*
|
||||
|
@ -43,122 +18,23 @@ class BlockContentForm extends ContentEntityForm {
|
|||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* Constructs a BlockContentForm object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
|
||||
* The custom block storage.
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $block_content_type_storage
|
||||
* The custom block type storage.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, EntityStorageInterface $block_content_storage, EntityStorageInterface $block_content_type_storage, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($entity_manager);
|
||||
$this->blockContentStorage = $block_content_storage;
|
||||
$this->blockContentTypeStorage = $block_content_type_storage;
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager,
|
||||
$entity_manager->getStorage('block_content'),
|
||||
$entity_manager->getStorage('block_content_type'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\Entity\EntityForm::prepareEntity().
|
||||
*
|
||||
* Prepares the custom block object.
|
||||
*
|
||||
* Fills in a few default values, and then invokes
|
||||
* hook_block_content_prepare() on all modules.
|
||||
*/
|
||||
protected function prepareEntity() {
|
||||
$block = $this->entity;
|
||||
// Set up default values, if required.
|
||||
$block_type = $this->blockContentTypeStorage->load($block->bundle());
|
||||
if (!$block->isNew()) {
|
||||
$block->setRevisionLogMessage(NULL);
|
||||
}
|
||||
// Always use the default revision setting.
|
||||
$block->setNewRevision($block_type->shouldCreateNewRevision());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$block = $this->entity;
|
||||
$account = $this->currentUser();
|
||||
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
if ($this->operation == 'edit') {
|
||||
$form['#title'] = $this->t('Edit custom block %label', array('%label' => $block->label()));
|
||||
$form['#title'] = $this->t('Edit custom block %label', ['%label' => $block->label()]);
|
||||
}
|
||||
// Override the default CSS class name, since the user-defined custom block
|
||||
// type name in 'TYPE-block-form' potentially clashes with third-party class
|
||||
// names.
|
||||
$form['#attributes']['class'][0] = 'block-' . Html::getClass($block->bundle()) . '-form';
|
||||
|
||||
$form['advanced'] = array(
|
||||
'#type' => 'vertical_tabs',
|
||||
'#weight' => 99,
|
||||
);
|
||||
|
||||
// Add a log field if the "Create new revision" option is checked, or if the
|
||||
// current user has the ability to check that option.
|
||||
$form['revision_information'] = array(
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Revision information'),
|
||||
// Open by default when "Create new revision" is checked.
|
||||
'#open' => $block->isNewRevision(),
|
||||
'#group' => 'advanced',
|
||||
'#attributes' => array(
|
||||
'class' => array('block-content-form-revision-information'),
|
||||
),
|
||||
'#attached' => array(
|
||||
'library' => array('block_content/drupal.block_content'),
|
||||
),
|
||||
'#weight' => 20,
|
||||
'#access' => $block->isNewRevision() || $account->hasPermission('administer blocks'),
|
||||
);
|
||||
|
||||
$form['revision_information']['revision'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Create new revision'),
|
||||
'#default_value' => $block->isNewRevision(),
|
||||
'#access' => $account->hasPermission('administer blocks'),
|
||||
);
|
||||
|
||||
// Check the revision log checkbox when the log textarea is filled in.
|
||||
// This must not happen if "Create new revision" is enabled by default,
|
||||
// since the state would auto-disable the checkbox otherwise.
|
||||
if (!$block->isNewRevision()) {
|
||||
$form['revision_information']['revision']['#states'] = array(
|
||||
'checked' => array(
|
||||
'textarea[name="revision_log"]' => array('empty' => FALSE),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$form['revision_information']['revision_log'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Revision log message'),
|
||||
'#rows' => 4,
|
||||
'#default_value' => $block->getRevisionLog(),
|
||||
'#description' => $this->t('Briefly describe the changes you have made.'),
|
||||
);
|
||||
|
||||
return parent::form($form, $form_state, $block);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,20 +43,12 @@ class BlockContentForm extends ContentEntityForm {
|
|||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$block = $this->entity;
|
||||
|
||||
// Save as a new revision if requested to do so.
|
||||
if (!$form_state->isValueEmpty('revision')) {
|
||||
$block->setNewRevision();
|
||||
// If a new revision is created, save the current user as revision author.
|
||||
$block->setRevisionCreationTime(REQUEST_TIME);
|
||||
$block->setRevisionUserId(\Drupal::currentUser()->id());
|
||||
}
|
||||
|
||||
$insert = $block->isNew();
|
||||
$block->save();
|
||||
$context = array('@type' => $block->bundle(), '%info' => $block->label());
|
||||
$context = ['@type' => $block->bundle(), '%info' => $block->label()];
|
||||
$logger = $this->logger('block_content');
|
||||
$block_type = $this->blockContentTypeStorage->load($block->bundle());
|
||||
$t_args = array('@type' => $block_type->label(), '%info' => $block->label());
|
||||
$block_type = $this->getBundleEntity();
|
||||
$t_args = ['@type' => $block_type->label(), '%info' => $block->label()];
|
||||
|
||||
if ($insert) {
|
||||
$logger->notice('@type: added %info.', $context);
|
||||
|
@ -200,10 +68,10 @@ class BlockContentForm extends ContentEntityForm {
|
|||
}
|
||||
$form_state->setRedirect(
|
||||
'block.admin_add',
|
||||
array(
|
||||
[
|
||||
'plugin_id' => 'block_content:' . $block->uuid(),
|
||||
'theme' => $theme,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -5,36 +5,18 @@ namespace Drupal\block_content;
|
|||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for custom blocks.
|
||||
*/
|
||||
class BlockContentTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
|
||||
parent::entityFormAlter($form, $form_state, $entity);
|
||||
// Move the translation fieldset to a vertical tab.
|
||||
if (isset($form['translation'])) {
|
||||
$form['translation'] += array(
|
||||
'#group' => 'additional_settings',
|
||||
'#weight' => 100,
|
||||
'#attributes' => array(
|
||||
'class' => array('block-content-translation-options'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function entityFormTitle(EntityInterface $entity) {
|
||||
$block_type = BlockContentType::load($entity->bundle());
|
||||
return t('<em>Edit @type</em> @title', array('@type' => $block_type->label(), '@title' => $entity->label()));
|
||||
return t('<em>Edit @type</em> @title', ['@type' => $block_type->label(), '@title' => $entity->label()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,65 +25,65 @@ class BlockContentTypeForm extends BundleEntityFormBase {
|
|||
$form['#title'] = $this->t('Add custom block type');
|
||||
}
|
||||
else {
|
||||
$form['#title'] = $this->t('Edit %label custom block type', array('%label' => $block_type->label()));
|
||||
$form['#title'] = $this->t('Edit %label custom block type', ['%label' => $block_type->label()]);
|
||||
}
|
||||
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $block_type->label(),
|
||||
'#description' => t("Provide a label for this block type to help identify it in the administration pages."),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['id'] = array(
|
||||
];
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $block_type->id(),
|
||||
'#machine_name' => array(
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\block_content\Entity\BlockContentType::load',
|
||||
),
|
||||
],
|
||||
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
|
||||
);
|
||||
];
|
||||
|
||||
$form['description'] = array(
|
||||
$form['description'] = [
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => $block_type->getDescription(),
|
||||
'#description' => t('Enter a description for this block type.'),
|
||||
'#title' => t('Description'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['revision'] = array(
|
||||
$form['revision'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create new revision'),
|
||||
'#default_value' => $block_type->shouldCreateNewRevision(),
|
||||
'#description' => t('Create a new revision by default for this block type.'),
|
||||
);
|
||||
];
|
||||
|
||||
if ($this->moduleHandler->moduleExists('language')) {
|
||||
$form['language'] = array(
|
||||
$form['language'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Language settings'),
|
||||
'#group' => 'additional_settings',
|
||||
);
|
||||
];
|
||||
|
||||
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
|
||||
$form['language']['language_configuration'] = array(
|
||||
$form['language']['language_configuration'] = [
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => array(
|
||||
'#entity_information' => [
|
||||
'entity_type' => 'block_content',
|
||||
'bundle' => $block_type->id(),
|
||||
),
|
||||
],
|
||||
'#default_value' => $language_configuration,
|
||||
);
|
||||
];
|
||||
|
||||
$form['#submit'][] = 'language_configuration_element_submit';
|
||||
}
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
];
|
||||
|
||||
return $this->protectBundleIdElement($form);
|
||||
}
|
||||
|
@ -98,13 +98,13 @@ class BlockContentTypeForm extends BundleEntityFormBase {
|
|||
$edit_link = $this->entity->link($this->t('Edit'));
|
||||
$logger = $this->logger('block_content');
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label())));
|
||||
$logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link));
|
||||
drupal_set_message(t('Custom block type %label has been updated.', ['%label' => $block_type->label()]));
|
||||
$logger->notice('Custom block type %label has been updated.', ['%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));
|
||||
drupal_set_message(t('Custom block type %label has been added.', ['%label' => $block_type->label()]));
|
||||
$logger->notice('Custom block type %label has been added.', ['%label' => $block_type->label(), 'link' => $edit_link]);
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Entity\RevisionableEntityBundleInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a custom block type entity.
|
||||
*/
|
||||
interface BlockContentTypeInterface extends ConfigEntityInterface {
|
||||
interface BlockContentTypeInterface extends ConfigEntityInterface, RevisionableEntityBundleInterface {
|
||||
|
||||
/**
|
||||
* Returns the description of the block type.
|
||||
|
@ -17,12 +18,4 @@ interface BlockContentTypeInterface extends ConfigEntityInterface {
|
|||
*/
|
||||
public function getDescription();
|
||||
|
||||
/**
|
||||
* Returns whether a new revision should be created by default.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if a new revision should be created by default.
|
||||
*/
|
||||
public function shouldCreateNewRevision();
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ class BlockContentViewBuilder extends EntityViewBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
|
||||
return $this->viewMultiple(array($entity), $view_mode, $langcode)[0];
|
||||
return $this->viewMultiple([$entity], $view_mode, $langcode)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
|
||||
public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
|
||||
$build_list = parent::viewMultiple($entities, $view_mode, $langcode);
|
||||
// Apply the buildMultiple() #pre_render callback immediately, to make
|
||||
// bubbling of attributes and contextual links to the actual block work.
|
||||
|
@ -48,10 +48,10 @@ class BlockContentViewBuilder extends EntityViewBuilder {
|
|||
parent::alterBuild($build, $entity, $display, $view_mode);
|
||||
// Add contextual links for this custom block.
|
||||
if (!$entity->isNew()) {
|
||||
$build['#contextual_links']['block_content'] = array(
|
||||
'route_parameters' => array('block_content' => $entity->id()),
|
||||
'metadata' => array('changed' => $entity->getChangedTime()),
|
||||
);
|
||||
$build['#contextual_links']['block_content'] = [
|
||||
'route_parameters' => ['block_content' => $entity->id()],
|
||||
'metadata' => ['changed' => $entity->getChangedTime()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,13 +23,13 @@ class BlockContentViewsData extends EntityViewsData {
|
|||
|
||||
$data['block_content_field_data']['type']['field']['id'] = 'field';
|
||||
|
||||
$data['block_content']['block_content_listing_empty'] = array(
|
||||
$data['block_content']['block_content_listing_empty'] = [
|
||||
'title' => $this->t('Empty block library behavior'),
|
||||
'help' => $this->t('Provides a link to add a new block.'),
|
||||
'area' => array(
|
||||
'area' => [
|
||||
'id' => 'block_content_listing_empty',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Advertise this table as a possible base table.
|
||||
$data['block_content_field_revision']['table']['base']['help'] = $this->t('Block Content revision is a history of changes to block content.');
|
||||
$data['block_content_field_revision']['table']['base']['defaults']['title'] = 'info';
|
||||
|
|
|
@ -79,14 +79,14 @@ class BlockContentController extends ControllerBase {
|
|||
return $this->addForm($type, $request);
|
||||
}
|
||||
if (count($types) === 0) {
|
||||
return array(
|
||||
return [
|
||||
'#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(),
|
||||
]),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return array('#theme' => 'block_content_add_list', '#content' => $types);
|
||||
return ['#theme' => 'block_content_add_list', '#content' => $types];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,9 +101,9 @@ class BlockContentController extends ControllerBase {
|
|||
* A form array as expected by drupal_render().
|
||||
*/
|
||||
public function addForm(BlockContentTypeInterface $block_content_type, Request $request) {
|
||||
$block = $this->blockContentStorage->create(array(
|
||||
$block = $this->blockContentStorage->create([
|
||||
'type' => $block_content_type->id()
|
||||
));
|
||||
]);
|
||||
if (($theme = $request->query->get('theme')) && in_array($theme, array_keys($this->themeHandler->listInfo()))) {
|
||||
// We have navigated to this page from the block library and will keep track
|
||||
// of the theme for redirecting the user to the configuration page for the
|
||||
|
@ -123,7 +123,7 @@ class BlockContentController extends ControllerBase {
|
|||
* The page title.
|
||||
*/
|
||||
public function getAddFormTitle(BlockContentTypeInterface $block_content_type) {
|
||||
return $this->t('Add %type custom block', array('%type' => $block_content_type->label()));
|
||||
return $this->t('Add %type custom block', ['%type' => $block_content_type->label()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ use Drupal\user\UserInterface;
|
|||
* base_table = "block_content",
|
||||
* revision_table = "block_content_revision",
|
||||
* data_table = "block_content_field_data",
|
||||
* revision_data_table = "block_content_field_revision",
|
||||
* show_revision_ui = TRUE,
|
||||
* links = {
|
||||
* "canonical" = "/block/{block_content}",
|
||||
* "delete-form" = "/block/{block_content}/delete",
|
||||
|
@ -120,7 +122,7 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstances() {
|
||||
return \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(array('plugin' => 'block_content:' . $this->uuid()));
|
||||
return \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['plugin' => 'block_content:' . $this->uuid()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,17 +174,24 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setRequired(TRUE)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -5,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->addConstraint('UniqueField', []);
|
||||
|
||||
$fields['revision_log'] = BaseFieldDefinition::create('string_long')
|
||||
->setLabel(t('Revision log message'))
|
||||
->setDescription(t('The log entry explaining the changes in this revision.'))
|
||||
->setRevisionable(TRUE);
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textarea',
|
||||
'weight' => 25,
|
||||
'settings' => [
|
||||
'rows' => 4,
|
||||
],
|
||||
]);
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
->setLabel(t('Changed'))
|
||||
|
|
|
@ -16,10 +16,10 @@ class BlockContentDeleteForm extends ContentEntityDeleteForm {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$instances = $this->entity->getInstances();
|
||||
|
||||
$form['message'] = array(
|
||||
$form['message'] = [
|
||||
'#markup' => $this->formatPlural(count($instances), 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instances.'),
|
||||
'#access' => !empty($instances),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -3,49 +3,23 @@
|
|||
namespace Drupal\block_content\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityDeleteForm;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a confirmation form for deleting a custom block type entity.
|
||||
*/
|
||||
class BlockContentTypeDeleteForm extends EntityDeleteForm {
|
||||
|
||||
/**
|
||||
* The query factory to create entity queries.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
public $queryFactory;
|
||||
|
||||
/**
|
||||
* Constructs a query factory object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
|
||||
* The entity query object.
|
||||
*/
|
||||
public function __construct(QueryFactory $query_factory) {
|
||||
$this->queryFactory = $query_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute();
|
||||
$blocks = $this->entityTypeManager->getStorage('block_content')->getQuery()
|
||||
->condition('type', $this->entity->id())
|
||||
->execute();
|
||||
if (!empty($blocks)) {
|
||||
$caption = '<p>' . $this->formatPlural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '</p>';
|
||||
$form['description'] = array('#markup' => $caption);
|
||||
$caption = '<p>' . $this->formatPlural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', ['%label' => $this->entity->label()]) . '</p>';
|
||||
$form['description'] = ['#markup' => $caption];
|
||||
return $form;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -105,11 +105,11 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'status' => TRUE,
|
||||
'info' => '',
|
||||
'view_mode' => 'full',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,14 +122,14 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
|
|||
$block = $this->entityManager->loadEntityByUuid('block_content', $uuid);
|
||||
$options = $this->entityManager->getViewModeOptionsByBundle('block_content', $block->bundle());
|
||||
|
||||
$form['view_mode'] = array(
|
||||
$form['view_mode'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#title' => $this->t('View mode'),
|
||||
'#description' => $this->t('Output the block in this view mode.'),
|
||||
'#default_value' => $this->configuration['view_mode'],
|
||||
'#access' => (count($options) > 1),
|
||||
);
|
||||
];
|
||||
$form['title']['#description'] = $this->t('The title of the block as shown to the user.');
|
||||
return $form;
|
||||
}
|
||||
|
@ -161,13 +161,13 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
|
|||
return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'#markup' => $this->t('Block with uuid %uuid does not exist. <a href=":url">Add custom block</a>.', array(
|
||||
return [
|
||||
'#markup' => $this->t('Block with uuid %uuid does not exist. <a href=":url">Add custom block</a>.', [
|
||||
'%uuid' => $this->getDerivativeId(),
|
||||
':url' => $this->urlGenerator->generate('block_content.add_page')
|
||||
)),
|
||||
]),
|
||||
'#access' => $this->account->hasPermission('administer blocks')
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,9 +50,9 @@ class BlockContent extends DeriverBase implements ContainerDeriverInterface {
|
|||
foreach ($block_contents as $block_content) {
|
||||
$this->derivatives[$block_content->uuid()] = $base_plugin_definition;
|
||||
$this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label();
|
||||
$this->derivatives[$block_content->uuid()]['config_dependencies']['content'] = array(
|
||||
$this->derivatives[$block_content->uuid()]['config_dependencies']['content'] = [
|
||||
$block_content->getConfigDependencyName()
|
||||
);
|
||||
];
|
||||
}
|
||||
return parent::getDerivativeDefinitions($base_plugin_definition);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class Box extends DrupalSqlBase {
|
|||
*/
|
||||
public function query() {
|
||||
$query = $this->select('boxes', 'b')
|
||||
->fields('b', array('bid', 'body', 'info', 'format'));
|
||||
->fields('b', ['bid', 'body', 'info', 'format']);
|
||||
$query->orderBy('b.bid');
|
||||
|
||||
return $query;
|
||||
|
@ -28,12 +28,12 @@ class Box extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'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.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,12 +24,12 @@ class BlockCustom extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'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.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,19 +71,19 @@ class ListingEmpty extends AreaPluginBase {
|
|||
public function render($empty = FALSE) {
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
/** @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())),
|
||||
$access_result = $this->accessManager->checkNamedRoute('block_content.add_page', [], $this->currentUser, TRUE);
|
||||
$element = [
|
||||
'#markup' => $this->t('Add a <a href=":url">custom block</a>.', [':url' => Url::fromRoute('block_content.add_page')->toString()]),
|
||||
'#access' => $access_result->isAllowed(),
|
||||
'#cache' => [
|
||||
'contexts' => $access_result->getCacheContexts(),
|
||||
'tags' => $access_result->getCacheTags(),
|
||||
'max-age' => $access_result->getCacheMaxAge(),
|
||||
],
|
||||
);
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content_test', 'dblog', 'field_ui');
|
||||
public static $modules = ['block_content_test', 'dblog', 'field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array(
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content display'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
|
@ -48,22 +48,22 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a block.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = 'Test Block';
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$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(
|
||||
$this->assertRaw(format_string('@block %name has been created.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]']
|
||||
)), 'Basic block created.');
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Check that the view mode setting is hidden because only one exists.
|
||||
$this->assertNoFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting hidden because only one exists');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
|
||||
$blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
|
@ -72,9 +72,9 @@ 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 custom block with block description %value already exists.', array(
|
||||
$this->assertRaw(format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $edit['info[0][value]']
|
||||
)));
|
||||
]));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
|
@ -83,40 +83,40 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
*/
|
||||
public function testBlockContentCreationMultipleViewModes() {
|
||||
// Add a new view mode and verify if it is selected as expected.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer display modes']));
|
||||
$this->drupalGet('admin/structure/display-modes/view/add/block_content');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => 'test_view_mode',
|
||||
'label' => 'Test View Mode',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('Saved the %label view mode.', array('%label' => $edit['label'])));
|
||||
$this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a block.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = 'Test Block';
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$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(
|
||||
$this->assertRaw(format_string('@block %name has been created.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]']
|
||||
)), 'Basic block created.');
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Save our block permanently
|
||||
$this->drupalPostForm(NULL, NULL, t('Save block'));
|
||||
$this->drupalPostForm(NULL, ['region' => 'content'], 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(
|
||||
$custom_view_mode = [
|
||||
'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.
|
||||
|
@ -134,6 +134,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
|
||||
|
||||
// Change the view mode.
|
||||
$view_mode['region'] = 'content';
|
||||
$view_mode['settings[view_mode]'] = 'test_view_mode';
|
||||
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
|
||||
|
||||
|
@ -142,7 +143,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]/@value', 'test_view_mode', 'View mode changed to Test View Mode');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
|
||||
$blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
|
@ -151,9 +152,9 @@ 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 custom block with block description %value already exists.', array(
|
||||
$this->assertRaw(format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $edit['info[0][value]']
|
||||
)));
|
||||
]));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
|
@ -164,20 +165,20 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
* type is being used.
|
||||
*/
|
||||
public function testDefaultBlockContentCreation() {
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
// Don't pass the custom block type in the url so the default is forced.
|
||||
$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(
|
||||
$this->assertRaw(format_string('@block %name has been created.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
)), 'Basic block created.');
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
|
||||
$blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Default Custom Block found in database.');
|
||||
}
|
||||
|
@ -198,7 +199,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
if (Database::getConnection()->supportsTransactions()) {
|
||||
// Check that the block does not exist in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', array('id'))
|
||||
->fields('b', ['id'])
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
@ -207,7 +208,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
else {
|
||||
// Check that the block exists in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', array('id'))
|
||||
->fields('b', ['id'])
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
@ -224,18 +225,18 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
*/
|
||||
public function testBlockDelete() {
|
||||
// Create a block.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Place the block.
|
||||
$instance = array(
|
||||
$instance = [
|
||||
'id' => Unicode::strtolower($edit['info[0][value]']),
|
||||
'settings[label]' => $edit['info[0][value]'],
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
];
|
||||
$block = BlockContent::load(1);
|
||||
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
@ -253,11 +254,11 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
$this->drupalGet('block/1/delete');
|
||||
$this->assertText(\Drupal::translation()->formatPlural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
|
||||
|
||||
$this->drupalPostForm(NULL, array(), 'Delete');
|
||||
$this->assertRaw(t('The custom block %name has been deleted.', array('%name' => $edit['info[0][value]'])));
|
||||
$this->drupalPostForm(NULL, [], 'Delete');
|
||||
$this->assertRaw(t('The custom block %name has been deleted.', ['%name' => $edit['info[0][value]']]));
|
||||
|
||||
// Create another block and force the plugin cache to flush.
|
||||
$edit2 = array();
|
||||
$edit2 = [];
|
||||
$edit2['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body2 = $this->randomMachineName(16);
|
||||
$edit2['body[0][value]'] = $body2;
|
||||
|
@ -267,7 +268,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
|
||||
// Create another block with no instances, and test we don't get a
|
||||
// confirmation message about deleting instances.
|
||||
$edit3 = array();
|
||||
$edit3 = [];
|
||||
$edit3['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit3['body[0][value]'] = $body;
|
||||
|
@ -285,16 +286,16 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
|||
$block = $this->createBlockContent();
|
||||
// Place the block.
|
||||
$block_placement_id = Unicode::strtolower($block->label());
|
||||
$instance = array(
|
||||
$instance = [
|
||||
'id' => $block_placement_id,
|
||||
'settings[label]' => $block->label(),
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
];
|
||||
$block = BlockContent::load(1);
|
||||
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
||||
$dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('content', array($block->getConfigDependencyName()));
|
||||
$dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('content', [$block->getConfigDependencyName()]);
|
||||
$block_placement = reset($dependencies);
|
||||
$this->assertEqual($block_placement_id, $block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ class BlockContentListTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_content', 'config_translation');
|
||||
public static $modules = ['block', 'block_content', 'config_translation'];
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer blocks', 'translate configuration')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'translate configuration']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
|
@ -39,7 +39,7 @@ class BlockContentListTest extends BlockContentTestBase {
|
|||
$this->assertEqual(count($elements), 2, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = array(t('Block description'), t('Operations'));
|
||||
$expected_items = [t('Block description'), t('Operations')];
|
||||
foreach ($elements as $key => $element) {
|
||||
$this->assertEqual($element[0], $expected_items[$key]);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class BlockContentListTest extends BlockContentTestBase {
|
|||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
@ -72,14 +72,14 @@ class BlockContentListTest extends BlockContentTestBase {
|
|||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(array('info' => $label));
|
||||
->loadByProperties(['info' => $label]);
|
||||
$block = reset($blocks);
|
||||
if (!empty($block)) {
|
||||
$this->assertLinkByHref('block/' . $block->id());
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', array('%label' => $label)) . ' | Drupal'));
|
||||
$edit = array('info[0][value]' => $new_label);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', ['%label' => $label]) . ' | Drupal'));
|
||||
$edit = ['info[0][value]' => $new_label];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
|
@ -95,8 +95,8 @@ class BlockContentListTest extends BlockContentTestBase {
|
|||
$delete_text = t('Delete');
|
||||
$this->clickLink($delete_text);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', array('%label' => $new_label)) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, array(), $delete_text);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', ['%label' => $new_label]) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, [], $delete_text);
|
||||
|
||||
// Verify that the text of the label and machine name does not appear in
|
||||
// the list (though it may appear elsewhere on the page).
|
||||
|
|
|
@ -22,7 +22,7 @@ class BlockContentListViewsTest extends BlockContentTestBase {
|
|||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer blocks', 'translate configuration')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'translate configuration']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
|
@ -58,7 +58,7 @@ class BlockContentListViewsTest extends BlockContentTestBase {
|
|||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
@ -79,14 +79,14 @@ class BlockContentListViewsTest extends BlockContentTestBase {
|
|||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(array('info' => $label));
|
||||
->loadByProperties(['info' => $label]);
|
||||
$block = reset($blocks);
|
||||
if (!empty($block)) {
|
||||
$this->assertLinkByHref('block/' . $block->id());
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', array('%label' => $label)) . ' | Drupal'));
|
||||
$edit = array('info[0][value]' => $new_label);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', ['%label' => $label]) . ' | Drupal'));
|
||||
$edit = ['info[0][value]' => $new_label];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
|
@ -102,8 +102,8 @@ class BlockContentListViewsTest extends BlockContentTestBase {
|
|||
$delete_text = t('Delete');
|
||||
$this->clickLink($delete_text);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', array('%label' => $new_label)) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, array(), $delete_text);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', ['%label' => $new_label]) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, [], $delete_text);
|
||||
|
||||
// Verify that the text of the label and machine name does not appear in
|
||||
// the list (though it may appear elsewhere on the page).
|
||||
|
|
|
@ -8,6 +8,9 @@ use Drupal\simpletest\WebTestBase;
|
|||
|
||||
/**
|
||||
* Sets up block content types.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\block_content\Functional\BlockContentTestBase instead.
|
||||
*/
|
||||
abstract class BlockContentTestBase extends WebTestBase {
|
||||
|
||||
|
@ -28,16 +31,16 @@ abstract class BlockContentTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array(
|
||||
protected $permissions = [
|
||||
'administer blocks'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_content');
|
||||
public static $modules = ['block', 'block_content'];
|
||||
|
||||
/**
|
||||
* Whether or not to auto-create the basic block type during setup.
|
||||
|
@ -75,11 +78,11 @@ abstract class BlockContentTestBase extends WebTestBase {
|
|||
*/
|
||||
protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) {
|
||||
$title = $title ?: $this->randomMachineName();
|
||||
$block_content = BlockContent::create(array(
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en'
|
||||
));
|
||||
]);
|
||||
if ($block_content && $save === TRUE) {
|
||||
$block_content->save();
|
||||
}
|
||||
|
@ -98,11 +101,11 @@ abstract class BlockContentTestBase extends WebTestBase {
|
|||
* Created custom block type.
|
||||
*/
|
||||
protected function createBlockContentType($label, $create_body = FALSE) {
|
||||
$bundle = BlockContentType::create(array(
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $label,
|
||||
'label' => $label,
|
||||
'revision' => FALSE,
|
||||
));
|
||||
]);
|
||||
$bundle->save();
|
||||
if ($create_body) {
|
||||
block_content_add_body_field($bundle->id());
|
||||
|
|
|
@ -19,13 +19,13 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
public static $modules = [
|
||||
'language',
|
||||
'content_translation',
|
||||
'block',
|
||||
'field_ui',
|
||||
'block_content'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -57,11 +57,11 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
*/
|
||||
protected function setupBundle() {
|
||||
// Create the basic bundle since it is provided by standard.
|
||||
$bundle = BlockContentType::create(array(
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $this->bundle,
|
||||
'label' => $this->bundle,
|
||||
'revision' => FALSE
|
||||
));
|
||||
]);
|
||||
$bundle->save();
|
||||
}
|
||||
|
||||
|
@ -69,12 +69,12 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTranslatorPermissions() {
|
||||
return array_merge(parent::getTranslatorPermissions(), array(
|
||||
return array_merge(parent::getTranslatorPermissions(), [
|
||||
'translate any entity',
|
||||
'access administration pages',
|
||||
'administer blocks',
|
||||
'administer block_content fields'
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,11 +93,11 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
protected function createBlockContent($title = FALSE, $bundle = FALSE) {
|
||||
$title = $title ?: $this->randomMachineName();
|
||||
$bundle = $bundle ?: $this->bundle;
|
||||
$block_content = BlockContent::create(array(
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en'
|
||||
));
|
||||
]);
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNewEntityValues($langcode) {
|
||||
return array('info' => Unicode::strtolower($this->randomMachineName())) + parent::getNewEntityValues($langcode);
|
||||
return ['info' => Unicode::strtolower($this->randomMachineName())] + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,7 +135,7 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
$values = $this->getNewEntityValues($default_langcode);
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $storage->create(array('type' => 'basic') + $values);
|
||||
$entity = $storage->create(['type' => 'basic'] + $values);
|
||||
$entity->save();
|
||||
$entity->addTranslation('it', $values);
|
||||
|
||||
|
@ -159,11 +159,11 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
public function testDisabledBundle() {
|
||||
// Create a bundle that does not have translation enabled.
|
||||
$disabled_bundle = $this->randomMachineName();
|
||||
$bundle = BlockContentType::create(array(
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $disabled_bundle,
|
||||
'label' => $disabled_bundle,
|
||||
'revision' => FALSE
|
||||
));
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
// Create a block content for each bundle.
|
||||
|
@ -171,7 +171,7 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
$disabled_block_content = $this->createBlockContent(FALSE, $bundle->id());
|
||||
|
||||
// Make sure that only a single row was inserted into the block table.
|
||||
$rows = db_query('SELECT * FROM {block_content_field_data} WHERE id = :id', array(':id' => $enabled_block_content->id()))->fetchAll();
|
||||
$rows = db_query('SELECT * FROM {block_content_field_data} WHERE id = :id', [':id' => $enabled_block_content->id()])->fetchAll();
|
||||
$this->assertEqual(1, count($rows));
|
||||
}
|
||||
|
||||
|
@ -188,15 +188,15 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
foreach ($this->langcodes as $langcode) {
|
||||
// We only want to test the title for non-english translations.
|
||||
if ($langcode != 'en') {
|
||||
$options = array('language' => $languages[$langcode]);
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', array(
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', [
|
||||
'@type' => $entity->bundle(),
|
||||
'@title' => $entity->getTranslation($langcode)->label(),
|
||||
'%language' => $languages[$langcode]->getName(),
|
||||
));
|
||||
]);
|
||||
$this->assertRaw($title);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,17 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('field_ui');
|
||||
public static $modules = ['field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array(
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content fields'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether or not to create an initial block type.
|
||||
|
@ -56,10 +56,10 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
$this->clickLink('block type creation page');
|
||||
|
||||
// Create a block type via the user interface.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => 'foo',
|
||||
'label' => 'title for foo',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$block_type = BlockContentType::load('foo');
|
||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||
|
@ -107,9 +107,9 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
$this->assertRaw('Body', 'Body field was found.');
|
||||
|
||||
// Change the block type name.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'label' => 'Bar',
|
||||
);
|
||||
];
|
||||
$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'));
|
||||
|
@ -121,9 +121,9 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
$this->assertUrl(\Drupal::url('block_content.add_form', ['block_content_type' => 'basic'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
|
||||
|
||||
// Remove the body field.
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', [], t('Delete'));
|
||||
// Resave the settings for this type.
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', array(), t('Save'));
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', [], t('Save'));
|
||||
// Check that the body field doesn't exist.
|
||||
$this->drupalGet('block/add/basic');
|
||||
$this->assertNoRaw('Body', 'Body field was not found.');
|
||||
|
@ -146,7 +146,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
// Attempt to delete the block type, which should not be allowed.
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', array('%label' => $type->label())),
|
||||
t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', ['%label' => $type->label()]),
|
||||
'The block type will not be deleted until all blocks of that type are removed.'
|
||||
);
|
||||
$this->assertNoText(t('This action cannot be undone.'), 'The block type deletion confirmation form is not available.');
|
||||
|
@ -156,7 +156,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
// Attempt to delete the block type, which should now be allowed.
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('Are you sure you want to delete the custom block type %type?', array('%type' => $type->id())),
|
||||
t('Are you sure you want to delete the custom block type %type?', ['%type' => $type->id()]),
|
||||
'The block type is available for deletion.'
|
||||
);
|
||||
$this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.');
|
||||
|
@ -197,22 +197,22 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
$this->clickLink(t('Add custom block'));
|
||||
// The seven theme has markup inside the link, we cannot use clickLink().
|
||||
if ($default_theme == 'seven') {
|
||||
$options = $theme != $default_theme ? array('query' => array('theme' => $theme)) : array();
|
||||
$this->assertLinkByHref(\Drupal::url('block_content.add_form', array('block_content_type' => 'foo'), $options));
|
||||
$options = $theme != $default_theme ? ['query' => ['theme' => $theme]] : [];
|
||||
$this->assertLinkByHref(\Drupal::url('block_content.add_form', ['block_content_type' => 'foo'], $options));
|
||||
$this->drupalGet('block/add/foo', $options);
|
||||
}
|
||||
else {
|
||||
$this->clickLink('foo');
|
||||
}
|
||||
// Create a new block.
|
||||
$edit = array('info[0][value]' => $this->randomMachineName(8));
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]']));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$block = reset($blocks);
|
||||
$this->assertUrl(\Drupal::url('block.admin_add', array('plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme), array('absolute' => TRUE)));
|
||||
$this->drupalPostForm(NULL, array(), t('Save block'));
|
||||
$this->assertUrl(\Drupal::url('block.admin_display_theme', array('theme' => $theme), array('absolute' => TRUE, 'query' => array('block-placement' => Html::getClass($edit['info[0][value]'])))));
|
||||
$this->assertUrl(\Drupal::url('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme], ['absolute' => TRUE]));
|
||||
$this->drupalPostForm(NULL, ['region' => 'content'], t('Save block'));
|
||||
$this->assertUrl(\Drupal::url('block.admin_display_theme', ['theme' => $theme], ['absolute' => TRUE, 'query' => ['block-placement' => Html::getClass($edit['info[0][value]'])]]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
|
@ -225,11 +225,11 @@ class BlockContentTypeTest extends BlockContentTestBase {
|
|||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
$this->clickLink('foo');
|
||||
$edit = array('info[0][value]' => $this->randomMachineName(8));
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]']));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$this->assertUrl(\Drupal::url('entity.block_content.collection', array(), array('absolute' => TRUE)));
|
||||
$this->assertUrl(\Drupal::url('entity.block_content.collection', [], ['absolute' => TRUE]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests adding revision_user and revision_created fields.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class BlockContentUpdateEntityFields extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that email token in status_blocked of user.mail is updated.
|
||||
*/
|
||||
public function testAddingFields() {
|
||||
$this->runUpdates();
|
||||
|
||||
$post_revision_created = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_created', 'block_content');
|
||||
$post_revision_user = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_user', 'block_content');
|
||||
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
|
||||
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
|
||||
|
||||
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
|
||||
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests update functions for the Block Content module.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class BlockContentUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the revision metadata fields and revision data table additions.
|
||||
*/
|
||||
public function testSimpleUpdates() {
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
|
||||
$this->assertNull($entity_type->getRevisionDataTable());
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
$post_revision_created = $entity_definition_update_manager->getFieldStorageDefinition('revision_created', 'block_content');
|
||||
$post_revision_user = $entity_definition_update_manager->getFieldStorageDefinition('revision_user', 'block_content');
|
||||
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
|
||||
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
|
||||
|
||||
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
|
||||
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
|
||||
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
|
||||
$this->assertEqual('block_content_field_revision', $entity_type->getRevisionDataTable());
|
||||
}
|
||||
|
||||
}
|
|
@ -15,14 +15,14 @@ class BlockContentFieldFilterTest extends BlockContentTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_field_filters');
|
||||
public static $testViews = ['test_field_filters'];
|
||||
|
||||
/**
|
||||
* List of block_content infos by language.
|
||||
|
@ -35,7 +35,7 @@ class BlockContentFieldFilterTest extends BlockContentTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function setUp() {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Add two new languages.
|
||||
|
@ -49,15 +49,15 @@ class BlockContentFieldFilterTest extends BlockContentTestBase {
|
|||
$field_storage->save();
|
||||
|
||||
// Set up block_content infos.
|
||||
$this->blockContentInfos = array(
|
||||
$this->blockContentInfos = [
|
||||
'en' => 'Food in Paris',
|
||||
'es' => 'Comida en Paris',
|
||||
'fr' => 'Nouriture en Paris',
|
||||
);
|
||||
];
|
||||
|
||||
// Create block_content with translations.
|
||||
$block_content = $this->createBlockContent(['info' => $this->blockContentInfos['en'], 'langcode' => 'en', 'type' => 'basic', 'body' => [['value' => $this->blockContentInfos['en']]]]);
|
||||
foreach (array('es', 'fr') as $langcode) {
|
||||
foreach (['es', 'fr'] as $langcode) {
|
||||
$translation = $block_content->addTranslation($langcode, ['info' => $this->blockContentInfos[$langcode]]);
|
||||
$translation->body->value = $this->blockContentInfos[$langcode];
|
||||
}
|
||||
|
@ -70,19 +70,19 @@ class BlockContentFieldFilterTest extends BlockContentTestBase {
|
|||
public function testFilters() {
|
||||
// Test the info filter page, which filters for info contains 'Comida'.
|
||||
// Should show just the Spanish translation, once.
|
||||
$this->assertPageCounts('test-info-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida info filter');
|
||||
$this->assertPageCounts('test-info-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida info filter');
|
||||
|
||||
// Test the body filter page, which filters for body contains 'Comida'.
|
||||
// Should show just the Spanish translation, once.
|
||||
$this->assertPageCounts('test-body-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida body filter');
|
||||
$this->assertPageCounts('test-body-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida body filter');
|
||||
|
||||
// Test the info Paris filter page, which filters for info contains
|
||||
// 'Paris'. Should show each translation once.
|
||||
$this->assertPageCounts('test-info-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris info filter');
|
||||
$this->assertPageCounts('test-info-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris info filter');
|
||||
|
||||
// Test the body Paris filter page, which filters for body contains
|
||||
// 'Paris'. Should show each translation once.
|
||||
$this->assertPageCounts('test-body-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris body filter');
|
||||
$this->assertPageCounts('test-body-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris body filter');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,23 +14,23 @@ class BlockContentIntegrationTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_block_content_view');
|
||||
public static $testViews = ['test_block_content_view'];
|
||||
|
||||
/**
|
||||
* Tests basic block_content view with a block_content_type argument.
|
||||
*/
|
||||
public function testBlockContentViewTypeArgument() {
|
||||
// Create two content types with three block_contents each.
|
||||
$types = array();
|
||||
$all_ids = array();
|
||||
$block_contents = array();
|
||||
$types = [];
|
||||
$all_ids = [];
|
||||
$block_contents = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$type = $this->createBlockContentType();
|
||||
$types[] = $type;
|
||||
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
// Ensure the right order of the block_contents.
|
||||
$block_content = $this->createBlockContent(array('type' => $type->id()));
|
||||
$block_content = $this->createBlockContent(['type' => $type->id()]);
|
||||
$block_contents[$type->id()][$block_content->id()] = $block_content;
|
||||
$all_ids[] = $block_content->id();
|
||||
}
|
||||
|
@ -55,9 +55,9 @@ class BlockContentIntegrationTest extends BlockContentTestBase {
|
|||
* @param array $expected_ids
|
||||
* An array of block_content IDs.
|
||||
*/
|
||||
protected function assertIds(array $expected_ids = array()) {
|
||||
protected function assertIds(array $expected_ids = []) {
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$ids = array();
|
||||
$ids = [];
|
||||
foreach ($result as $element) {
|
||||
$ids[] = (int) $element;
|
||||
}
|
||||
|
|
|
@ -21,18 +21,18 @@ class BlockContentRedirectTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_content', 'views');
|
||||
public static $modules = ['block', 'block_content', 'views'];
|
||||
|
||||
/**
|
||||
* Tests the redirect destination when editing block content.
|
||||
*/
|
||||
public function testRedirectDestination() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer blocks')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Create a custom block.
|
||||
$this->clickLink('custom block');
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = 'Test redirect destination';
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, 'Save');
|
||||
|
|
|
@ -25,26 +25,26 @@ abstract class BlockContentTestBase extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array(
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_content', 'block_content_test_views');
|
||||
public static $modules = ['block', 'block_content', 'block_content_test_views'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
// Ensure the basic bundle exists. This is provided by the standard profile.
|
||||
$this->createBlockContentType(array('id' => 'basic'));
|
||||
$this->createBlockContentType(['id' => 'basic']);
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||
|
||||
if ($import_test_views) {
|
||||
ViewTestData::createTestViews(get_class($this), array('block_content_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['block_content_test_views']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,17 +58,17 @@ abstract class BlockContentTestBase extends ViewTestBase {
|
|||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent(array $settings = array()) {
|
||||
protected function createBlockContent(array $settings = []) {
|
||||
$status = 0;
|
||||
$settings += array(
|
||||
$settings += [
|
||||
'info' => $this->randomMachineName(),
|
||||
'type' => 'basic',
|
||||
'langcode' => 'en',
|
||||
);
|
||||
];
|
||||
if ($block_content = BlockContent::create($settings)) {
|
||||
$status = $block_content->save();
|
||||
}
|
||||
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content %info.', array('%info' => $block_content->label())));
|
||||
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content %info.', ['%info' => $block_content->label()]));
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ abstract class BlockContentTestBase extends ViewTestBase {
|
|||
* @return \Drupal\block_content\Entity\BlockContentType
|
||||
* Created custom block type.
|
||||
*/
|
||||
protected function createBlockContentType(array $values = array()) {
|
||||
protected function createBlockContentType(array $values = []) {
|
||||
// Find a non-existent random type name.
|
||||
if (!isset($values['id'])) {
|
||||
do {
|
||||
|
@ -91,16 +91,16 @@ abstract class BlockContentTestBase extends ViewTestBase {
|
|||
else {
|
||||
$id = $values['id'];
|
||||
}
|
||||
$values += array(
|
||||
$values += [
|
||||
'id' => $id,
|
||||
'label' => $id,
|
||||
'revision' => FALSE
|
||||
);
|
||||
];
|
||||
$bundle = BlockContentType::create($values);
|
||||
$status = $bundle->save();
|
||||
block_content_add_body_field($bundle->id());
|
||||
|
||||
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content type %bundle.', array('%bundle' => $bundle->id())));
|
||||
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content type %bundle.', ['%bundle' => $bundle->id()]));
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,18 +16,18 @@ class FieldTypeTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_field_type');
|
||||
public static $testViews = ['test_field_type'];
|
||||
|
||||
public function testFieldType() {
|
||||
$block_content = $this->createBlockContent();
|
||||
$expected_result[] = array(
|
||||
$expected_result[] = [
|
||||
'id' => $block_content->id(),
|
||||
'type' => $block_content->bundle(),
|
||||
);
|
||||
$column_map = array(
|
||||
];
|
||||
$column_map = [
|
||||
'id' => 'id',
|
||||
'type:target_id' => 'type',
|
||||
);
|
||||
];
|
||||
|
||||
$view = Views::getView('test_field_type');
|
||||
$this->executeView($view);
|
||||
|
|
|
@ -20,72 +20,72 @@ class RevisionRelationshipsTest extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content' , 'block_content_test_views');
|
||||
public static $modules = ['block_content' , 'block_content_test_views'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_block_content_revision_id', 'test_block_content_revision_revision_id');
|
||||
public static $testViews = ['test_block_content_revision_id', 'test_block_content_revision_revision_id'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
BlockContentType::create(array(
|
||||
BlockContentType::create([
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => TRUE,
|
||||
));
|
||||
ViewTestData::createTestViews(get_class($this), array('block_content_test_views'));
|
||||
]);
|
||||
ViewTestData::createTestViews(get_class($this), ['block_content_test_views']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a block_content with revision and rest result count for both views.
|
||||
*/
|
||||
public function testBlockContentRevisionRelationship() {
|
||||
$block_content = BlockContent::create(array(
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $this->randomMachineName(),
|
||||
'type' => 'basic',
|
||||
'langcode' => 'en',
|
||||
));
|
||||
]);
|
||||
$block_content->save();
|
||||
// Create revision of the block_content.
|
||||
$block_content_revision = clone $block_content;
|
||||
$block_content_revision->setNewRevision();
|
||||
$block_content_revision->save();
|
||||
$column_map = array(
|
||||
$column_map = [
|
||||
'revision_id' => 'revision_id',
|
||||
'id_1' => 'id_1',
|
||||
'block_content_field_data_block_content_field_revision_id' => 'block_content_field_data_block_content_field_revision_id',
|
||||
);
|
||||
];
|
||||
|
||||
// Here should be two rows.
|
||||
$view_id = Views::getView('test_block_content_revision_id');
|
||||
$this->executeView($view_id, array($block_content->id()));
|
||||
$resultset_id = array(
|
||||
array(
|
||||
$this->executeView($view_id, [$block_content->id()]);
|
||||
$resultset_id = [
|
||||
[
|
||||
'revision_id' => '1',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'revision_id' => '2',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->assertIdenticalResultset($view_id, $resultset_id, $column_map);
|
||||
|
||||
// There should be only one row with active revision 2.
|
||||
$view_revision_id = Views::getView('test_block_content_revision_revision_id');
|
||||
$this->executeView($view_revision_id, array($block_content->id()));
|
||||
$resultset_revision_id = array(
|
||||
array(
|
||||
$this->executeView($view_revision_id, [$block_content->id()]);
|
||||
$resultset_revision_id = [
|
||||
[
|
||||
'revision_id' => '2',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->assertIdenticalResultset($view_revision_id, $resultset_revision_id, $column_map);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@ use Drupal\block_content\Entity\BlockContent;
|
|||
*/
|
||||
function block_content_test_block_content_view(array &$build, BlockContent $block_content, $view_mode) {
|
||||
// Add extra content.
|
||||
$build['extra_content'] = array(
|
||||
$build['extra_content'] = [
|
||||
'#markup' => '<blink>Yowser</blink>',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
|
@ -20,29 +20,29 @@ class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('block_content');
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$block_content_type = BlockContentType::create(array(
|
||||
$block_content_type = BlockContentType::create([
|
||||
'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 = BlockContent::create(array(
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Llama',
|
||||
'type' => 'basic',
|
||||
'body' => array(
|
||||
'body' => [
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
return $block_content;
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Create a block and test block access by attempting to view the block.
|
||||
|
@ -14,7 +14,7 @@ class BlockContentPageViewTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content_test');
|
||||
public static $modules = ['block_content_test'];
|
||||
|
||||
/**
|
||||
* Checks block edit and fallback functionality.
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\user\Entity\User;
|
||||
|
@ -37,8 +37,8 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
|||
// Create initial block.
|
||||
$block = $this->createBlockContent('initial');
|
||||
|
||||
$blocks = array();
|
||||
$logs = array();
|
||||
$blocks = [];
|
||||
$logs = [];
|
||||
|
||||
// Get original block.
|
||||
$blocks[] = $block->getRevisionId();
|
||||
|
@ -70,11 +70,13 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
|||
foreach ($blocks as $delta => $revision_id) {
|
||||
// Confirm the correct revision text appears.
|
||||
/** @var \Drupal\block_content\BlockContentInterface $loaded */
|
||||
$loaded = entity_revision_load('block_content', $revision_id);
|
||||
$loaded = $this->container->get('entity_type.manager')
|
||||
->getStorage('block_content')
|
||||
->loadRevision($revision_id);
|
||||
// Verify revision log is the same.
|
||||
$this->assertEqual($loaded->getRevisionLogMessage(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
|
||||
$this->assertEqual($loaded->getRevisionLogMessage(), $logs[$delta], format_string('Correct log message found for revision @revision', [
|
||||
'@revision' => $loaded->getRevisionId(),
|
||||
)));
|
||||
]));
|
||||
if ($delta > 0) {
|
||||
$this->assertTrue($loaded->getRevisionUser() instanceof UserInterface, 'Revision User found.');
|
||||
$this->assertTrue(is_numeric($loaded->getRevisionUserId()), 'Revision User ID found.');
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
|
@ -16,7 +16,7 @@ class BlockContentSaveTest extends BlockContentTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block_content_test');
|
||||
public static $modules = ['block_content_test'];
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
|
@ -35,12 +35,12 @@ class BlockContentSaveTest extends BlockContentTestBase {
|
|||
$max_id = db_query('SELECT MAX(id) FROM {block_content}')->fetchField();
|
||||
$test_id = $max_id + mt_rand(1000, 1000000);
|
||||
$info = $this->randomMachineName(8);
|
||||
$block_array = array(
|
||||
$block_array = [
|
||||
'info' => $info,
|
||||
'body' => array('value' => $this->randomMachineName(32)),
|
||||
'body' => ['value' => $this->randomMachineName(32)],
|
||||
'type' => 'basic',
|
||||
'id' => $test_id
|
||||
);
|
||||
];
|
||||
$block = BlockContent::create($block_array);
|
||||
$block->enforceIsNew(TRUE);
|
||||
$block->save();
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Sets up block content types.
|
||||
*/
|
||||
abstract class BlockContentTestBase extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Profile to use.
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
/**
|
||||
* Admin user
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks'
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content'];
|
||||
|
||||
/**
|
||||
* Whether or not to auto-create the basic block type during setup.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $autoCreateBasicBlockType = TRUE;
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
if ($this->autoCreateBasicBlockType) {
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
}
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block.
|
||||
*
|
||||
* @param bool|string $title
|
||||
* (optional) Title of block. When no value is given uses a random name.
|
||||
* 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', $save = TRUE) {
|
||||
$title = $title ?: $this->randomMachineName();
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en'
|
||||
]);
|
||||
if ($block_content && $save === TRUE) {
|
||||
$block_content->save();
|
||||
}
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block type (bundle).
|
||||
*
|
||||
* @param string $label
|
||||
* The block type label.
|
||||
* @param bool $create_body
|
||||
* Whether or not to create the body field
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContentType
|
||||
* Created custom block type.
|
||||
*/
|
||||
protected function createBlockContentType($label, $create_body = FALSE) {
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $label,
|
||||
'label' => $label,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
if ($create_body) {
|
||||
block_content_add_body_field($bundle->id());
|
||||
}
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
@ -27,7 +27,7 @@ class PageEditTest extends BlockContentTestBase {
|
|||
$title_key = 'info[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
// Create block to edit.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = Unicode::strtolower($this->randomMachineName(8));
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
@ -43,7 +43,7 @@ class PageEditTest extends BlockContentTestBase {
|
|||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
|
||||
// Edit the content of the block.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit[$title_key] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
// Stay on the current page, without reloading.
|
||||
|
@ -51,21 +51,21 @@ class PageEditTest extends BlockContentTestBase {
|
|||
|
||||
// Edit the same block, creating a new revision.
|
||||
$this->drupalGet("block/" . $block->id());
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$edit['revision'] = TRUE;
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Ensure that the block revision has been created.
|
||||
\Drupal::entityManager()->getStorage('block_content')->resetCache(array($block->id()));
|
||||
\Drupal::entityManager()->getStorage('block_content')->resetCache([$block->id()]);
|
||||
$revised_block = BlockContent::load($block->id());
|
||||
$this->assertNotIdentical($block->getRevisionId(), $revised_block->getRevisionId(), 'A new revision has been created.');
|
||||
|
||||
// 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?', ['@label' => $revised_block->label()]));
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
|||
*/
|
||||
class MigrateBlockContentBodyFieldTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = array('block', 'block_content', 'filter', 'text');
|
||||
public static $modules = ['block', 'block_content', 'filter', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -13,7 +13,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
|||
*/
|
||||
class MigrateBlockContentTypeTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = array('block', 'block_content', 'filter', 'text');
|
||||
public static $modules = ['block', 'block_content', 'filter', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -13,11 +13,11 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
|||
*/
|
||||
class MigrateCustomBlockTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = array(
|
||||
public static $modules = [
|
||||
'block_content',
|
||||
'filter',
|
||||
'text',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -13,32 +13,32 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||
class BlockContentLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
$this->directoryList = [
|
||||
'block' => 'core/modules/block',
|
||||
'block_content' => 'core/modules/block_content',
|
||||
);
|
||||
];
|
||||
parent::setUp();
|
||||
|
||||
$config_factory = $this->getConfigFactoryStub(array('system.theme' => array(
|
||||
$config_factory = $this->getConfigFactoryStub(['system.theme' => [
|
||||
'default' => 'test_c',
|
||||
)));
|
||||
]]);
|
||||
|
||||
$themes = array();
|
||||
$themes['test_a'] = (object) array(
|
||||
$themes = [];
|
||||
$themes['test_a'] = (object) [
|
||||
'status' => 0,
|
||||
);
|
||||
$themes['test_b'] = (object) array(
|
||||
];
|
||||
$themes['test_b'] = (object) [
|
||||
'status' => 1,
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'test_b',
|
||||
),
|
||||
);
|
||||
$themes['test_c'] = (object) array(
|
||||
],
|
||||
];
|
||||
$themes['test_c'] = (object) [
|
||||
'status' => 1,
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'test_c',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
|
||||
$theme_handler->expects($this->any())
|
||||
->method('listInfo')
|
||||
|
@ -56,25 +56,25 @@ class BlockContentLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* @dataProvider getBlockContentListingRoutes
|
||||
*/
|
||||
public function testBlockContentListLocalTasks($route) {
|
||||
$this->assertLocalTasks($route, array(
|
||||
0 => array(
|
||||
$this->assertLocalTasks($route, [
|
||||
0 => [
|
||||
'block.admin_display',
|
||||
'entity.block_content.collection',
|
||||
),
|
||||
1 => array(
|
||||
],
|
||||
1 => [
|
||||
'block_content.list_sub',
|
||||
'entity.block_content_type.collection',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getBlockContentListingRoutes() {
|
||||
return array(
|
||||
array('entity.block_content.collection', 'entity.block_content_type.collection'),
|
||||
);
|
||||
return [
|
||||
['entity.block_content.collection', 'entity.block_content_type.collection'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue