Move all files to 2017/
This commit is contained in:
parent
ac7370f67f
commit
2875863330
15717 changed files with 0 additions and 0 deletions
11
2017/web/core/modules/block_content/block_content.info.yml
Normal file
11
2017/web/core/modules/block_content/block_content.info.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
name: 'Custom Block'
|
||||
type: module
|
||||
description: 'Allows the creation of custom blocks through the user interface.'
|
||||
package: Core
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- drupal:block
|
||||
- drupal:text
|
||||
- drupal:user
|
||||
configure: entity.block_content.collection
|
140
2017/web/core/modules/block_content/block_content.install
Normal file
140
2017/web/core/modules/block_content/block_content.install
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the block_content module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Add 'revision_translation_affected' field to 'block_content' entities.
|
||||
*/
|
||||
function block_content_update_8001() {
|
||||
// Install the definition that this field had in
|
||||
// \Drupal\block_content\Entity\BlockContent::baseFieldDefinitions()
|
||||
// at the time that this update function was written. If/when code is
|
||||
// deployed that changes that definition, the corresponding module must
|
||||
// implement an update function that invokes
|
||||
// \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
|
||||
// with the new definition.
|
||||
$storage_definition = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Revision translation affected'))
|
||||
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generalizes the d6_block_content_type and d6_block_content_body_field
|
||||
* migrations.
|
||||
*/
|
||||
function block_content_update_8002() {
|
||||
// Removed in issue #2569605. The Migrate and Migrate Drupal modules are
|
||||
// marked experimental and do not need to support the update path until they
|
||||
// are stable.
|
||||
// @see https://www.drupal.org/node/2569469
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'revision_created' and 'revision_user' fields to 'block_content' entities.
|
||||
*/
|
||||
function block_content_update_8003() {
|
||||
$revision_created = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Revision create time'))
|
||||
->setDescription(t('The time that the current revision was created.'))
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('revision_created', 'block_content', 'block_content', $revision_created);
|
||||
|
||||
$revision_user = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Revision user'))
|
||||
->setDescription(t('The user ID of the author of the current revision.'))
|
||||
->setSetting('target_type', 'user')
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
\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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a publishing status field for block_content entities.
|
||||
*/
|
||||
function block_content_update_8400() {
|
||||
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
|
||||
// Add the published entity key to the block_content entity type.
|
||||
$entity_type = $definition_update_manager->getEntityType('block_content');
|
||||
$entity_keys = $entity_type->getKeys();
|
||||
$entity_keys['published'] = 'status';
|
||||
$entity_type->set('entity_keys', $entity_keys);
|
||||
$definition_update_manager->updateEntityType($entity_type);
|
||||
|
||||
// Add the publishing status field to the block_content entity type.
|
||||
$status = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(new TranslatableMarkup('Publishing status'))
|
||||
->setDescription(new TranslatableMarkup('A boolean indicating the published state.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
$has_content_translation_status_field = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
|
||||
if ($has_content_translation_status_field) {
|
||||
$status->setInitialValueFromField('content_translation_status', TRUE);
|
||||
}
|
||||
else {
|
||||
$status->setInitialValue(TRUE);
|
||||
}
|
||||
$definition_update_manager->installFieldStorageDefinition('status', 'block_content', 'block_content', $status);
|
||||
|
||||
// Uninstall the 'content_translation_status' field if needed.
|
||||
$database = \Drupal::database();
|
||||
if ($has_content_translation_status_field) {
|
||||
// First we have to remove the field data.
|
||||
$database->update($entity_type->getDataTable())
|
||||
->fields(['content_translation_status' => NULL])
|
||||
->execute();
|
||||
|
||||
// A site may have disabled revisionability for this entity type.
|
||||
if ($entity_type->isRevisionable()) {
|
||||
$database->update($entity_type->getRevisionDataTable())
|
||||
->fields(['content_translation_status' => NULL])
|
||||
->execute();
|
||||
}
|
||||
|
||||
$content_translation_status = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
|
||||
$definition_update_manager->uninstallFieldStorageDefinition($content_translation_status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'reusable' field to 'block_content' entities.
|
||||
*/
|
||||
function block_content_update_8600() {
|
||||
$reusable = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Reusable'))
|
||||
->setDescription(t('A boolean indicating whether this block is reusable.'))
|
||||
->setTranslatable(FALSE)
|
||||
->setRevisionable(FALSE)
|
||||
->setDefaultValue(TRUE)
|
||||
->setInitialValue(TRUE);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('reusable', 'block_content', 'block_content', $reusable);
|
||||
}
|
|
@ -0,0 +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: {}
|
||||
dependencies:
|
||||
- core/drupal.entity-form
|
|
@ -0,0 +1,13 @@
|
|||
block_content_type_add:
|
||||
route_name: block_content.type_add
|
||||
title: 'Add custom block type'
|
||||
appears_on:
|
||||
- entity.block_content_type.collection
|
||||
|
||||
block_content_add_action:
|
||||
route_name: block_content.add_page
|
||||
title: 'Add custom block'
|
||||
appears_on:
|
||||
- block.admin_library
|
||||
- entity.block_content.collection
|
||||
class: \Drupal\block_content\Plugin\Menu\LocalAction\BlockContentAddLocalAction
|
|
@ -0,0 +1,4 @@
|
|||
block_content.block_edit:
|
||||
title: 'Edit'
|
||||
group: block_content
|
||||
route_name: 'entity.block_content.canonical'
|
|
@ -0,0 +1,28 @@
|
|||
entity.block_content.collection:
|
||||
title: 'Custom block library'
|
||||
route_name: entity.block_content.collection
|
||||
base_route: block.admin_display
|
||||
block_content.list_sub:
|
||||
title: Blocks
|
||||
route_name: entity.block_content.collection
|
||||
parent_id: entity.block_content.collection
|
||||
entity.block_content_type.collection:
|
||||
title: Block types
|
||||
route_name: entity.block_content_type.collection
|
||||
parent_id: entity.block_content.collection
|
||||
weight: 1
|
||||
|
||||
entity.block_content.canonical:
|
||||
title: Edit
|
||||
route_name: entity.block_content.canonical
|
||||
base_route: entity.block_content.canonical
|
||||
entity.block_content.delete_form:
|
||||
title: Delete
|
||||
route_name: entity.block_content.delete_form
|
||||
base_route: entity.block_content.canonical
|
||||
|
||||
# Default tab for custom block type editing.
|
||||
entity.block_content_type.edit_form:
|
||||
title: 'Edit'
|
||||
route_name: entity.block_content_type.edit_form
|
||||
base_route: entity.block_content_type.edit_form
|
180
2017/web/core/modules/block_content/block_content.module
Normal file
180
2017/web/core/modules/block_content/block_content.module
Normal file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Allows the creation of custom blocks through the user interface.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Database\Query\AlterableInterface;
|
||||
use Drupal\Core\Database\Query\ConditionInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
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', ['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>.', [':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>.', [':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.', [':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.', [':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.', [':block-library' => \Drupal::url('entity.block_content.collection')]) . '</p>';
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function block_content_theme($existing, $type, $theme, $path) {
|
||||
return [
|
||||
'block_content_add_list' => [
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'block_content.pages.inc',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
function block_content_entity_type_alter(array &$entity_types) {
|
||||
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
|
||||
// Add a translation handler for fields if the language module is enabled.
|
||||
if (\Drupal::moduleHandler()->moduleExists('language')) {
|
||||
$translation = $entity_types['block_content']->get('translation');
|
||||
$translation['block_content'] = TRUE;
|
||||
$entity_types['block_content']->set('translation', $translation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the default body field to a custom block type.
|
||||
*
|
||||
* @param string $block_type_id
|
||||
* Id of the block type.
|
||||
* @param string $label
|
||||
* (optional) The label for the body instance. Defaults to 'Body'
|
||||
*
|
||||
* @return \Drupal\field\Entity\FieldConfig
|
||||
* A Body field object.
|
||||
*/
|
||||
function block_content_add_body_field($block_type_id, $label = 'Body') {
|
||||
// Add or remove the body field, as needed.
|
||||
$field = FieldConfig::loadByName('block_content', $block_type_id, 'body');
|
||||
if (empty($field)) {
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
|
||||
'bundle' => $block_type_id,
|
||||
'label' => $label,
|
||||
'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', [
|
||||
'type' => 'text_textarea_with_summary',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Assign display settings for 'default' view mode.
|
||||
entity_get_display('block_content', $block_type_id, 'default')
|
||||
->setComponent('body', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter().
|
||||
*
|
||||
* Alters any 'entity_reference' query where the entity type is
|
||||
* 'block_content' and the query has the tag 'block_content_access'.
|
||||
*
|
||||
* These queries should only return reusable blocks unless a condition on
|
||||
* 'reusable' is explicitly set.
|
||||
*
|
||||
* Block_content entities that are reusable should by default not be selectable
|
||||
* as entity reference values. A module can still create an instance of
|
||||
* \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface
|
||||
* that will allow selection of non-reusable blocks by explicitly setting
|
||||
* a condition on the 'reusable' field.
|
||||
*
|
||||
* @see \Drupal\block_content\BlockContentAccessControlHandler
|
||||
*/
|
||||
function block_content_query_entity_reference_alter(AlterableInterface $query) {
|
||||
if ($query instanceof SelectInterface && $query->getMetaData('entity_type') === 'block_content' && $query->hasTag('block_content_access')) {
|
||||
$data_table = \Drupal::entityTypeManager()->getDefinition('block_content')->getDataTable();
|
||||
if (array_key_exists($data_table, $query->getTables()) && !_block_content_has_reusable_condition($query->conditions(), $query->getTables())) {
|
||||
$query->condition("$data_table.reusable", TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to find nested conditions using the reusable field.
|
||||
*
|
||||
* @todo Replace this function with a call to the API in
|
||||
* https://www.drupal.org/project/drupal/issues/2984930
|
||||
*
|
||||
* @param array $condition
|
||||
* The condition or condition group to check.
|
||||
* @param array $tables
|
||||
* The tables from the related select query.
|
||||
*
|
||||
* @see \Drupal\Core\Database\Query\SelectInterface::getTables
|
||||
*
|
||||
* @return bool
|
||||
* Whether the conditions contain any condition using the reusable field.
|
||||
*/
|
||||
function _block_content_has_reusable_condition(array $condition, array $tables) {
|
||||
// If this is a condition group call this function recursively for each nested
|
||||
// condition until a condition is found that return TRUE.
|
||||
if (isset($condition['#conjunction'])) {
|
||||
foreach (array_filter($condition, 'is_array') as $nested_condition) {
|
||||
if (_block_content_has_reusable_condition($nested_condition, $tables)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
if (isset($condition['field'])) {
|
||||
$field = $condition['field'];
|
||||
if (is_object($field) && $field instanceof ConditionInterface) {
|
||||
return _block_content_has_reusable_condition($field->conditions(), $tables);
|
||||
}
|
||||
$field_parts = explode('.', $field);
|
||||
$data_table = \Drupal::entityTypeManager()->getDefinition('block_content')->getDataTable();
|
||||
foreach ($tables as $table) {
|
||||
if ($table['table'] === $data_table && $field_parts[0] === $table['alias'] && $field_parts[1] === 'reusable') {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return FALSE;
|
||||
}
|
36
2017/web/core/modules/block_content/block_content.pages.inc
Normal file
36
2017/web/core/modules/block_content/block_content.pages.inc
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides page callbacks for custom blocks.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Prepares variables for a custom block type creation list templates.
|
||||
*
|
||||
* Default template: block-content-add-list.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - content: An array of block types.
|
||||
*
|
||||
* @see block_content_add_page()
|
||||
*/
|
||||
function template_preprocess_block_content_add_list(&$variables) {
|
||||
$variables['types'] = [];
|
||||
$query = \Drupal::request()->query->all();
|
||||
foreach ($variables['content'] as $type) {
|
||||
$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' => [
|
||||
'query' => $query,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Post update functions for Custom Block.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
|
||||
/**
|
||||
* Adds a 'reusable' filter to all Custom Block views.
|
||||
*/
|
||||
function block_content_post_update_add_views_reusable_filter(&$sandbox = NULL) {
|
||||
$entity_type = \Drupal::entityTypeManager()->getDefinition('block_content');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('block_content');
|
||||
|
||||
// If the storage class is an instance SqlContentEntityStorage we can use it
|
||||
// to determine the table to use, otherwise we have to get the table from the
|
||||
// entity type.
|
||||
if ($storage instanceof SqlContentEntityStorage) {
|
||||
$table = $entity_type->isTranslatable() ? $storage->getDataTable() : $storage->getBaseTable();
|
||||
}
|
||||
else {
|
||||
$table = $entity_type->isTranslatable() ? $entity_type->getDataTable() : $entity_type->getBaseTable();
|
||||
}
|
||||
// If we were not able to get a table name we can not update the views.
|
||||
if (empty($table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
\Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view', function ($view) use ($table) {
|
||||
/** @var \Drupal\views\ViewEntityInterface $view */
|
||||
if ($view->get('base_table') !== $table) {
|
||||
return FALSE;
|
||||
}
|
||||
$save_view = FALSE;
|
||||
$displays = $view->get('display');
|
||||
foreach ($displays as $display_name => &$display) {
|
||||
// Update the default display and displays that have overridden filters.
|
||||
if (!isset($display['display_options']['filters']['reusable']) &&
|
||||
($display_name === 'default' || isset($display['display_options']['filters']))) {
|
||||
$display['display_options']['filters']['reusable'] = [
|
||||
'id' => 'reusable',
|
||||
'table' => $table,
|
||||
'field' => 'reusable',
|
||||
'relationship' => 'none',
|
||||
'group_type' => 'group',
|
||||
'admin_label' => '',
|
||||
'operator' => '=',
|
||||
'value' => '1',
|
||||
'group' => 1,
|
||||
'exposed' => FALSE,
|
||||
'expose' => [
|
||||
'operator_id' => '',
|
||||
'label' => '',
|
||||
'description' => '',
|
||||
'use_operator' => FALSE,
|
||||
'operator' => '',
|
||||
'identifier' => '',
|
||||
'required' => FALSE,
|
||||
'remember' => FALSE,
|
||||
'multiple' => FALSE,
|
||||
],
|
||||
'is_grouped' => FALSE,
|
||||
'group_info' => [
|
||||
'label' => '',
|
||||
'description' => '',
|
||||
'identifier' => '',
|
||||
'optional' => TRUE,
|
||||
'widget' => 'select',
|
||||
'multiple' => FALSE,
|
||||
'remember' => FALSE,
|
||||
'default_group' => 'All',
|
||||
'default_group_multiple' => [],
|
||||
'group_items' => [],
|
||||
],
|
||||
'entity_type' => 'block_content',
|
||||
'entity_field' => 'reusable',
|
||||
'plugin_id' => 'boolean',
|
||||
];
|
||||
$save_view = TRUE;
|
||||
}
|
||||
}
|
||||
if ($save_view) {
|
||||
$view->set('display', $displays);
|
||||
}
|
||||
return $save_view;
|
||||
});
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
block_content.add_page:
|
||||
path: '/block/add'
|
||||
defaults:
|
||||
_controller: '\Drupal\block_content\Controller\BlockContentController::add'
|
||||
_title: 'Add custom block'
|
||||
options:
|
||||
_admin_route: TRUE
|
||||
requirements:
|
||||
_permission: 'administer blocks'
|
||||
|
||||
block_content.add_form:
|
||||
path: '/block/add/{block_content_type}'
|
||||
defaults:
|
||||
_controller: '\Drupal\block_content\Controller\BlockContentController::addForm'
|
||||
_title_callback: 'Drupal\block_content\Controller\BlockContentController::getAddFormTitle'
|
||||
options:
|
||||
_admin_route: TRUE
|
||||
requirements:
|
||||
_permission: 'administer blocks'
|
||||
|
||||
entity.block_content.canonical:
|
||||
path: '/block/{block_content}'
|
||||
defaults:
|
||||
_entity_form: 'block_content.edit'
|
||||
options:
|
||||
_admin_route: TRUE
|
||||
requirements:
|
||||
_entity_access: 'block_content.update'
|
||||
block_content: \d+
|
||||
|
||||
entity.block_content.edit_form:
|
||||
path: '/block/{block_content}'
|
||||
defaults:
|
||||
_entity_form: 'block_content.edit'
|
||||
options:
|
||||
_admin_route: TRUE
|
||||
requirements:
|
||||
_entity_access: 'block_content.update'
|
||||
block_content: \d+
|
||||
|
||||
entity.block_content.delete_form:
|
||||
path: '/block/{block_content}/delete'
|
||||
defaults:
|
||||
_entity_form: 'block_content.delete'
|
||||
_title: 'Delete'
|
||||
options:
|
||||
_admin_route: TRUE
|
||||
requirements:
|
||||
_entity_access: 'block_content.delete'
|
||||
block_content: \d+
|
||||
|
||||
block_content.type_add:
|
||||
path: '/admin/structure/block/block-content/types/add'
|
||||
defaults:
|
||||
_entity_form: 'block_content_type.add'
|
||||
_title: 'Add'
|
||||
requirements:
|
||||
_permission: 'administer blocks'
|
||||
|
||||
entity.block_content.collection:
|
||||
path: '/admin/structure/block/block-content'
|
||||
defaults:
|
||||
_title: 'Custom block library'
|
||||
_entity_list: 'block_content'
|
||||
requirements:
|
||||
_permission: 'administer blocks'
|
|
@ -0,0 +1,6 @@
|
|||
services:
|
||||
block_content.uuid_lookup:
|
||||
class: \Drupal\block_content\BlockContentUuidLookup
|
||||
arguments: ['@cache.bootstrap', '@lock', '@entity_type.manager']
|
||||
tags:
|
||||
- { name: needs_destruction }
|
|
@ -0,0 +1,9 @@
|
|||
langcode: en
|
||||
status: false
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: block_content.full
|
||||
label: Full
|
||||
targetEntityType: block_content
|
||||
cache: true
|
|
@ -0,0 +1,18 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- text
|
||||
id: block_content.body
|
||||
field_name: body
|
||||
entity_type: block_content
|
||||
type: text_with_summary
|
||||
settings: { }
|
||||
module: text
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: true
|
||||
custom_storage: false
|
|
@ -0,0 +1,535 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- user
|
||||
id: block_content
|
||||
label: 'Custom block library'
|
||||
module: views
|
||||
description: 'Find and manage custom blocks.'
|
||||
tag: default
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'administer blocks'
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: mini
|
||||
options:
|
||||
items_per_page: 50
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
tags:
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
override: true
|
||||
sticky: false
|
||||
caption: ''
|
||||
summary: ''
|
||||
description: ''
|
||||
columns:
|
||||
info: info
|
||||
type: type
|
||||
changed: changed
|
||||
operations: operations
|
||||
info:
|
||||
info:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
type:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
changed:
|
||||
sortable: true
|
||||
default_sort_order: desc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
operations:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
default: changed
|
||||
empty_table: true
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Block description'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings:
|
||||
link_to_entity: true
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
entity_type: null
|
||||
entity_field: info
|
||||
plugin_id: field
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Block type'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: target_id
|
||||
type: entity_reference_label
|
||||
settings:
|
||||
link: false
|
||||
group_column: target_id
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: field
|
||||
changed:
|
||||
id: changed
|
||||
table: block_content_field_data
|
||||
field: changed
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Updated
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
entity_type: block_content
|
||||
entity_field: changed
|
||||
type: timestamp
|
||||
settings:
|
||||
date_format: short
|
||||
custom_date_format: ''
|
||||
timezone: ''
|
||||
plugin_id: field
|
||||
operations:
|
||||
id: operations
|
||||
table: block_content
|
||||
field: operations
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Operations
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
destination: true
|
||||
entity_type: block_content
|
||||
plugin_id: entity_operations
|
||||
filters:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: info_op
|
||||
label: 'Block description'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: info_op
|
||||
identifier: info
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
plugin_id: string
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Block type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
reusable:
|
||||
id: reusable
|
||||
table: block_content_field_data
|
||||
field: reusable
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '='
|
||||
value: '1'
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: reusable
|
||||
plugin_id: boolean
|
||||
sorts: { }
|
||||
title: 'Custom block library'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty:
|
||||
area_text_custom:
|
||||
id: area_text_custom
|
||||
table: views
|
||||
field: area_text_custom
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: true
|
||||
tokenize: false
|
||||
content: 'There are no custom blocks available.'
|
||||
plugin_id: text_custom
|
||||
block_content_listing_empty:
|
||||
admin_label: ''
|
||||
empty: true
|
||||
field: block_content_listing_empty
|
||||
group_type: group
|
||||
id: block_content_listing_empty
|
||||
label: ''
|
||||
relationship: none
|
||||
table: block_content
|
||||
plugin_id: block_content_listing_empty
|
||||
entity_type: block_content
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
max-age: 0
|
||||
tags: { }
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: admin/structure/block/block-content
|
||||
menu:
|
||||
type: tab
|
||||
title: 'Custom block library'
|
||||
description: ''
|
||||
parent: block.admin_display
|
||||
weight: 0
|
||||
context: '0'
|
||||
menu_name: admin
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
max-age: 0
|
||||
tags: { }
|
|
@ -0,0 +1,18 @@
|
|||
# Schema for the configuration files of the Custom Block module.
|
||||
|
||||
block_content.type.*:
|
||||
type: config_entity
|
||||
label: 'Custom block type settings'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
revision:
|
||||
type: integer
|
||||
label: 'Create new revision'
|
||||
description:
|
||||
type: text
|
||||
label: 'Description'
|
|
@ -0,0 +1,37 @@
|
|||
id: block_content_body_field
|
||||
label: Block content body field configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
-
|
||||
entity_type: block_content
|
||||
bundle: basic
|
||||
field_name: body
|
||||
label: Body
|
||||
display_summary: false
|
||||
ids:
|
||||
entity_type:
|
||||
type: string
|
||||
bundle:
|
||||
type: string
|
||||
field_name:
|
||||
type: string
|
||||
source_module: block
|
||||
process:
|
||||
entity_type: entity_type
|
||||
bundle: bundle
|
||||
field_name: field_name
|
||||
label: label
|
||||
'settings/display_summary': display_summary
|
||||
destination:
|
||||
plugin: entity:field_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- block_content_type
|
||||
provider:
|
||||
- block_content
|
||||
- migrate_drupal
|
|
@ -0,0 +1,40 @@
|
|||
id: block_content_entity_display
|
||||
label: Body field display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
-
|
||||
entity_type: block_content
|
||||
bundle: basic
|
||||
view_mode: default
|
||||
field_name: body
|
||||
options:
|
||||
label: hidden
|
||||
ids:
|
||||
entity_type:
|
||||
type: string
|
||||
bundle:
|
||||
type: string
|
||||
view_mode:
|
||||
type: string
|
||||
field_name:
|
||||
type: string
|
||||
source_module: block
|
||||
process:
|
||||
entity_type: entity_type
|
||||
bundle: bundle
|
||||
view_mode: view_mode
|
||||
field_name: field_name
|
||||
options: options
|
||||
destination:
|
||||
plugin: component_entity_display
|
||||
migration_dependencies:
|
||||
required:
|
||||
- block_content_body_field
|
||||
provider:
|
||||
- block_content
|
||||
- migrate_drupal
|
|
@ -0,0 +1,37 @@
|
|||
id: block_content_entity_form_display
|
||||
label: Body field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
-
|
||||
entity_type: block_content
|
||||
bundle: basic
|
||||
form_mode: default
|
||||
field_name: body
|
||||
ids:
|
||||
entity_type:
|
||||
type: string
|
||||
bundle:
|
||||
type: string
|
||||
form_mode:
|
||||
type: string
|
||||
field_name:
|
||||
type: string
|
||||
source_module: block
|
||||
process:
|
||||
entity_type: entity_type
|
||||
bundle: bundle
|
||||
form_mode: form_mode
|
||||
field_name: field_name
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
||||
required:
|
||||
- block_content_body_field
|
||||
provider:
|
||||
- block_content
|
||||
- migrate_drupal
|
|
@ -0,0 +1,24 @@
|
|||
id: block_content_type
|
||||
label: Block content type
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
-
|
||||
id: basic
|
||||
label: Basic
|
||||
ids:
|
||||
id:
|
||||
type: string
|
||||
source_module: block
|
||||
process:
|
||||
id: id
|
||||
label: label
|
||||
destination:
|
||||
plugin: entity:block_content_type
|
||||
provider:
|
||||
- block_content
|
||||
- migrate_drupal
|
|
@ -0,0 +1,24 @@
|
|||
id: d6_custom_block
|
||||
label: Custom blocks
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
source:
|
||||
plugin: d6_box
|
||||
process:
|
||||
id: bid
|
||||
info: info
|
||||
'body/format':
|
||||
plugin: migration_lookup
|
||||
migration: d6_filter_format
|
||||
source: format
|
||||
'body/value': body
|
||||
destination:
|
||||
plugin: entity:block_content
|
||||
default_bundle: basic
|
||||
no_stub: true
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_filter_format
|
||||
- block_content_body_field
|
|
@ -0,0 +1,24 @@
|
|||
id: d7_custom_block
|
||||
label: Custom blocks
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
source:
|
||||
plugin: d7_block_custom
|
||||
process:
|
||||
id: bid
|
||||
info: info
|
||||
'body/format':
|
||||
plugin: migration_lookup
|
||||
migration: d7_filter_format
|
||||
source: format
|
||||
'body/value': body
|
||||
destination:
|
||||
plugin: entity:block_content
|
||||
default_bundle: basic
|
||||
no_stub: true
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_filter_format
|
||||
- block_content_body_field
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* An access group where all the dependencies must be allowed.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class AccessGroupAnd implements AccessibleInterface {
|
||||
|
||||
/**
|
||||
* The access dependencies.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessibleInterface[]
|
||||
*/
|
||||
protected $dependencies = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addDependency(AccessibleInterface $dependency) {
|
||||
$this->dependencies[] = $dependency;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
$access_result = AccessResult::neutral();
|
||||
foreach (array_slice($this->dependencies, 1) as $dependency) {
|
||||
$access_result = $access_result->andIf($dependency->access($operation, $account, TRUE));
|
||||
}
|
||||
return $return_as_object ? $access_result : $access_result->isAllowed();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDependencies() {
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Access;
|
||||
|
||||
/**
|
||||
* Interface for AccessibleInterface objects that have an access dependency.
|
||||
*
|
||||
* Objects should implement this interface when their access depends on access
|
||||
* to another object that implements \Drupal\Core\Access\AccessibleInterface.
|
||||
* This interface simply provides the getter method for the access
|
||||
* dependency object. Objects that implement this interface are responsible for
|
||||
* checking access of the access dependency because the dependency may not take
|
||||
* effect in all cases. For instance an entity may only need the access
|
||||
* dependency set when it is embedded within another entity and its access
|
||||
* should be dependent on access to the entity in which it is embedded.
|
||||
*
|
||||
* To check the access to the dependency the object implementing this interface
|
||||
* can use code like this:
|
||||
* @code
|
||||
* $accessible->getAccessDependency()->access($op, $account, TRUE);
|
||||
* @endcode
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface DependentAccessInterface {
|
||||
|
||||
/**
|
||||
* Gets the access dependency.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessibleInterface|null
|
||||
* The access dependency or NULL if none has been set.
|
||||
*/
|
||||
public function getAccessDependency();
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
|
||||
/**
|
||||
* An interface to allow adding an access dependency.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface RefinableDependentAccessInterface extends DependentAccessInterface {
|
||||
|
||||
/**
|
||||
* Sets the access dependency.
|
||||
*
|
||||
* If an access dependency is already set this will replace the existing
|
||||
* dependency.
|
||||
*
|
||||
* @param \Drupal\Core\Access\AccessibleInterface $access_dependency
|
||||
* The object upon which access depends.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAccessDependency(AccessibleInterface $access_dependency);
|
||||
|
||||
/**
|
||||
* Adds an access dependency into the existing access dependency.
|
||||
*
|
||||
* If no existing dependency is currently set this will set the dependency
|
||||
* will be set to the new value.
|
||||
*
|
||||
* If there is an existing dependency and it is not an instance of
|
||||
* AccessGroupAnd the dependency will be set as a new AccessGroupAnd
|
||||
* instance with the existing and new dependencies as the members of the
|
||||
* group.
|
||||
*
|
||||
* If there is an existing dependency and it is a instance of AccessGroupAnd
|
||||
* the dependency will be added to the existing access group.
|
||||
*
|
||||
* @param \Drupal\Core\Access\AccessibleInterface $access_dependency
|
||||
* The access dependency to merge.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addAccessDependency(AccessibleInterface $access_dependency);
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
|
||||
/**
|
||||
* Trait for \Drupal\block_content\Access\RefinableDependentAccessInterface.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
trait RefinableDependentAccessTrait {
|
||||
|
||||
/**
|
||||
* The access dependency.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessibleInterface
|
||||
*/
|
||||
protected $accessDependency;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAccessDependency(AccessibleInterface $access_dependency) {
|
||||
$this->accessDependency = $access_dependency;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAccessDependency() {
|
||||
return $this->accessDependency;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addAccessDependency(AccessibleInterface $access_dependency) {
|
||||
if (empty($this->accessDependency)) {
|
||||
$this->accessDependency = $access_dependency;
|
||||
return $this;
|
||||
}
|
||||
if (!$this->accessDependency instanceof AccessGroupAnd) {
|
||||
$accessGroup = new AccessGroupAnd();
|
||||
$this->accessDependency = $accessGroup->addDependency($this->accessDependency);
|
||||
}
|
||||
$this->accessDependency->addDependency($access_dependency);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\block_content\Access\DependentAccessInterface;
|
||||
use Drupal\block_content\Event\BlockContentGetDependencyEvent;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityHandlerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Defines the access control handler for the custom block entity type.
|
||||
*
|
||||
* @see \Drupal\block_content\Entity\BlockContent
|
||||
*/
|
||||
class BlockContentAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* BlockContentAccessControlHandler constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||
* The event dispatcher.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EventDispatcherInterface $dispatcher) {
|
||||
parent::__construct($entity_type);
|
||||
$this->eventDispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
|
||||
return new static(
|
||||
$entity_type,
|
||||
$container->get('event_dispatcher')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
if ($operation === 'view') {
|
||||
$access = AccessResult::allowedIf($entity->isPublished())
|
||||
->orIf(AccessResult::allowedIfHasPermission($account, 'administer blocks'));
|
||||
}
|
||||
else {
|
||||
$access = parent::checkAccess($entity, $operation, $account);
|
||||
}
|
||||
// Add the entity as a cacheable dependency because access will at least be
|
||||
// determined by whether the block is reusable.
|
||||
$access->addCacheableDependency($entity);
|
||||
/** @var \Drupal\block_content\BlockContentInterface $entity */
|
||||
if ($entity->isReusable() === FALSE) {
|
||||
if (!$entity instanceof DependentAccessInterface) {
|
||||
throw new \LogicException("Non-reusable block entities must implement \Drupal\block_content\Access\DependentAccessInterface for access control.");
|
||||
}
|
||||
$dependency = $entity->getAccessDependency();
|
||||
if (empty($dependency)) {
|
||||
// If an access dependency has not been set let modules set one.
|
||||
$event = new BlockContentGetDependencyEvent($entity);
|
||||
$this->eventDispatcher->dispatch(BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY, $event);
|
||||
$dependency = $event->getAccessDependency();
|
||||
if (empty($dependency)) {
|
||||
return AccessResult::forbidden("Non-reusable blocks must set an access dependency for access control.");
|
||||
}
|
||||
}
|
||||
/** @var \Drupal\Core\Entity\EntityInterface $dependency */
|
||||
$access = $access->andIf($dependency->access($operation, $account, TRUE));
|
||||
}
|
||||
return $access;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
/**
|
||||
* Defines events for the block_content module.
|
||||
*
|
||||
* @see \Drupal\block_content\Event\BlockContentGetDependencyEvent
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class BlockContentEvents {
|
||||
|
||||
/**
|
||||
* Name of the event when getting the dependency of a non-reusable block.
|
||||
*
|
||||
* This event allows modules to provide a dependency for non-reusable block
|
||||
* access if
|
||||
* \Drupal\block_content\Access\DependentAccessInterface::getAccessDependency()
|
||||
* did not return a dependency during access checking.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @see \Drupal\block_content\Event\BlockContentGetDependencyEvent
|
||||
* @see \Drupal\block_content\BlockContentAccessControlHandler::checkAccess()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const BLOCK_CONTENT_GET_DEPENDENCY = 'block_content.get_dependency';
|
||||
|
||||
}
|
91
2017/web/core/modules/block_content/src/BlockContentForm.php
Normal file
91
2017/web/core/modules/block_content/src/BlockContentForm.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form handler for the custom block edit forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* The block content entity.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$block = $this->entity;
|
||||
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
if ($this->operation == 'edit') {
|
||||
$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';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$block = $this->entity;
|
||||
|
||||
$insert = $block->isNew();
|
||||
$block->save();
|
||||
$context = ['@type' => $block->bundle(), '%info' => $block->label()];
|
||||
$logger = $this->logger('block_content');
|
||||
$block_type = $this->getBundleEntity();
|
||||
$t_args = ['@type' => $block_type->label(), '%info' => $block->label()];
|
||||
|
||||
if ($insert) {
|
||||
$logger->notice('@type: added %info.', $context);
|
||||
$this->messenger()->addStatus($this->t('@type %info has been created.', $t_args));
|
||||
}
|
||||
else {
|
||||
$logger->notice('@type: updated %info.', $context);
|
||||
$this->messenger()->addStatus($this->t('@type %info has been updated.', $t_args));
|
||||
}
|
||||
|
||||
if ($block->id()) {
|
||||
$form_state->setValue('id', $block->id());
|
||||
$form_state->set('id', $block->id());
|
||||
if ($insert) {
|
||||
if (!$theme = $block->getTheme()) {
|
||||
$theme = $this->config('system.theme')->get('default');
|
||||
}
|
||||
$form_state->setRedirect(
|
||||
'block.admin_add',
|
||||
[
|
||||
'plugin_id' => 'block_content:' . $block->uuid(),
|
||||
'theme' => $theme,
|
||||
]
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form_state->setRedirectUrl($block->urlInfo('collection'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// In the unlikely case something went wrong on save, the block will be
|
||||
// rebuilt and block form redisplayed.
|
||||
$this->messenger()->addError($this->t('The block could not be saved.'));
|
||||
$form_state->setRebuild();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\block_content\Access\RefinableDependentAccessInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a custom block entity.
|
||||
*/
|
||||
interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface, EntityPublishedInterface, RefinableDependentAccessInterface {
|
||||
|
||||
/**
|
||||
* Returns the block revision log message.
|
||||
*
|
||||
* @return string
|
||||
* The revision log message.
|
||||
*
|
||||
* @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage() instead.
|
||||
*/
|
||||
public function getRevisionLog();
|
||||
|
||||
/**
|
||||
* Sets the block description.
|
||||
*
|
||||
* @param string $info
|
||||
* The block description.
|
||||
*
|
||||
* @return \Drupal\block_content\BlockContentInterface
|
||||
* The class instance that this method is called on.
|
||||
*/
|
||||
public function setInfo($info);
|
||||
|
||||
/**
|
||||
* Sets the block revision log message.
|
||||
*
|
||||
* @param string $revision_log
|
||||
* The revision log message.
|
||||
*
|
||||
* @return \Drupal\block_content\BlockContentInterface
|
||||
* The class instance that this method is called on.
|
||||
*
|
||||
* @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage() instead.
|
||||
*/
|
||||
public function setRevisionLog($revision_log);
|
||||
|
||||
/**
|
||||
* Determines if the block is reusable or not.
|
||||
*
|
||||
* @return bool
|
||||
* Returns TRUE if reusable and FALSE otherwise.
|
||||
*/
|
||||
public function isReusable();
|
||||
|
||||
/**
|
||||
* Sets the block to be reusable.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setReusable();
|
||||
|
||||
/**
|
||||
* Sets the block to be non-reusable.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setNonReusable();
|
||||
|
||||
/**
|
||||
* Sets the theme value.
|
||||
*
|
||||
* When creating a new block content block from the block library, the user is
|
||||
* redirected to the configure form for that block in the given theme. The
|
||||
* theme is stored against the block when the block content add form is shown.
|
||||
*
|
||||
* @param string $theme
|
||||
* The theme name.
|
||||
*
|
||||
* @return \Drupal\block_content\BlockContentInterface
|
||||
* The class instance that this method is called on.
|
||||
*/
|
||||
public function setTheme($theme);
|
||||
|
||||
/**
|
||||
* Gets the theme value.
|
||||
*
|
||||
* When creating a new block content block from the block library, the user is
|
||||
* redirected to the configure form for that block in the given theme. The
|
||||
* theme is stored against the block when the block content add form is shown.
|
||||
*
|
||||
* @return string
|
||||
* The theme name.
|
||||
*/
|
||||
public function getTheme();
|
||||
|
||||
/**
|
||||
* Gets the configured instances of this custom block.
|
||||
*
|
||||
* @return array
|
||||
* Array of Drupal\block\Core\Plugin\Entity\Block entities.
|
||||
*/
|
||||
public function getInstances();
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of custom block entities.
|
||||
*
|
||||
* @see \Drupal\block_content\Entity\BlockContent
|
||||
*/
|
||||
class BlockContentListBuilder extends EntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = t('Block description');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $entity->label();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEntityIds() {
|
||||
$query = $this->getStorage()->getQuery()
|
||||
->sort($this->entityType->getKey('id'));
|
||||
$query->condition('reusable', TRUE);
|
||||
|
||||
// Only add the pager if a limit is specified.
|
||||
if ($this->limit) {
|
||||
$query->pager($this->limit);
|
||||
}
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for custom blocks.
|
||||
*/
|
||||
class BlockContentTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function entityFormTitle(EntityInterface $entity) {
|
||||
$block_type = BlockContentType::load($entity->bundle());
|
||||
return t('<em>Edit @type</em> @title', ['@type' => $block_type->label(), '@title' => $entity->label()]);
|
||||
}
|
||||
|
||||
}
|
115
2017/web/core/modules/block_content/src/BlockContentTypeForm.php
Normal file
115
2017/web/core/modules/block_content/src/BlockContentTypeForm.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Entity\BundleEntityFormBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
|
||||
/**
|
||||
* The block content type entity form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentTypeForm extends BundleEntityFormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
/* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
|
||||
$block_type = $this->entity;
|
||||
|
||||
if ($this->operation == 'add') {
|
||||
$form['#title'] = $this->t('Add custom block type');
|
||||
}
|
||||
else {
|
||||
$form['#title'] = $this->t('Edit %label custom block type', ['%label' => $block_type->label()]);
|
||||
}
|
||||
|
||||
$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'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $block_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\block_content\Entity\BlockContentType::load',
|
||||
],
|
||||
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
|
||||
];
|
||||
|
||||
$form['description'] = [
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => $block_type->getDescription(),
|
||||
'#description' => t('Enter a description for this block type.'),
|
||||
'#title' => t('Description'),
|
||||
];
|
||||
|
||||
$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'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Language settings'),
|
||||
'#group' => 'additional_settings',
|
||||
];
|
||||
|
||||
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
|
||||
$form['language']['language_configuration'] = [
|
||||
'#type' => 'language_configuration',
|
||||
'#entity_information' => [
|
||||
'entity_type' => 'block_content',
|
||||
'bundle' => $block_type->id(),
|
||||
],
|
||||
'#default_value' => $language_configuration,
|
||||
];
|
||||
|
||||
$form['#submit'][] = 'language_configuration_element_submit';
|
||||
}
|
||||
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
];
|
||||
|
||||
return $this->protectBundleIdElement($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$block_type = $this->entity;
|
||||
$status = $block_type->save();
|
||||
|
||||
$edit_link = $this->entity->link($this->t('Edit'));
|
||||
$logger = $this->logger('block_content');
|
||||
if ($status == SAVED_UPDATED) {
|
||||
$this->messenger()->addStatus(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());
|
||||
$this->messenger()->addStatus(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'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
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, RevisionableEntityBundleInterface {
|
||||
|
||||
/**
|
||||
* Returns the description of the block type.
|
||||
*
|
||||
* @return string
|
||||
* The description of the type of this block.
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of custom block type entities.
|
||||
*
|
||||
* @see \Drupal\block_content\Entity\BlockContentType
|
||||
*/
|
||||
class BlockContentTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOperations(EntityInterface $entity) {
|
||||
$operations = parent::getDefaultOperations($entity);
|
||||
// Place the edit operation after the operations added by field_ui.module
|
||||
// which have the weights 15, 20, 25.
|
||||
if (isset($operations['edit'])) {
|
||||
$operations['edit']['weight'] = 30;
|
||||
}
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['type'] = t('Block type');
|
||||
$header['description'] = t('Description');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['type'] = $entity->link();
|
||||
$row['description']['data']['#markup'] = $entity->getDescription();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTitle() {
|
||||
return $this->t('Custom block types');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\CacheCollector;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Lock\LockBackendInterface;
|
||||
|
||||
/**
|
||||
* A cache collector that caches IDs for block_content UUIDs.
|
||||
*
|
||||
* As block_content entities are used as block plugin derivatives, it is a
|
||||
* fairly safe limitation that there are not hundreds of them, a site will
|
||||
* likely run into problems with too many block content entities in other places
|
||||
* than a cache that only stores UUID's and IDs. The same assumption is not true
|
||||
* for other content entities.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentUuidLookup extends CacheCollector {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a BlockContentUuidLookup instance.
|
||||
*
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
|
||||
* The cache backend.
|
||||
* @param \Drupal\Core\Lock\LockBackendInterface $lock
|
||||
* The lock backend.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct('block_content_uuid', $cache, $lock);
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function resolveCacheMiss($key) {
|
||||
$ids = $this->entityTypeManager->getStorage('block_content')->getQuery()
|
||||
->condition('uuid', $key)
|
||||
->execute();
|
||||
|
||||
// Only cache if there is a match, otherwise creating new entities would
|
||||
// require to invalidate the cache.
|
||||
$id = reset($ids);
|
||||
if ($id) {
|
||||
$this->storage[$key] = $id;
|
||||
$this->persist($key);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityViewBuilder;
|
||||
|
||||
/**
|
||||
* View builder handler for custom blocks.
|
||||
*/
|
||||
class BlockContentViewBuilder extends EntityViewBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
|
||||
return $this->viewMultiple([$entity], $view_mode, $langcode)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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.
|
||||
// @see \Drupal\block\BlockViewBuilder::buildBlock()
|
||||
unset($build_list['#pre_render'][0]);
|
||||
return $this->buildMultiple($build_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
|
||||
$build = parent::getBuildDefaults($entity, $view_mode);
|
||||
// The custom block will be rendered in the wrapped block template already
|
||||
// and thus has no entity template itself.
|
||||
unset($build['#theme']);
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides the views data for the block_content entity type.
|
||||
*/
|
||||
class BlockContentViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
|
||||
$data = parent::getViewsData();
|
||||
|
||||
$data['block_content_field_data']['id']['field']['id'] = 'field';
|
||||
|
||||
$data['block_content_field_data']['info']['field']['id'] = 'field';
|
||||
$data['block_content_field_data']['info']['field']['link_to_entity default'] = TRUE;
|
||||
|
||||
$data['block_content_field_data']['type']['field']['id'] = 'field';
|
||||
|
||||
$data['block_content_field_data']['table']['wizard_id'] = 'block_content';
|
||||
|
||||
$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' => [
|
||||
'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';
|
||||
|
||||
// @todo EntityViewsData should add these relationships by default.
|
||||
// https://www.drupal.org/node/2410275
|
||||
$data['block_content_field_revision']['id']['relationship']['id'] = 'standard';
|
||||
$data['block_content_field_revision']['id']['relationship']['base'] = 'block_content_field_data';
|
||||
$data['block_content_field_revision']['id']['relationship']['base field'] = 'id';
|
||||
$data['block_content_field_revision']['id']['relationship']['title'] = $this->t('Block Content');
|
||||
$data['block_content_field_revision']['id']['relationship']['label'] = $this->t('Get the actual block content from a block content revision.');
|
||||
|
||||
$data['block_content_field_revision']['revision_id']['relationship']['id'] = 'standard';
|
||||
$data['block_content_field_revision']['revision_id']['relationship']['base'] = 'block_content_field_data';
|
||||
$data['block_content_field_revision']['revision_id']['relationship']['base field'] = 'revision_id';
|
||||
$data['block_content_field_revision']['revision_id']['relationship']['title'] = $this->t('Block Content');
|
||||
$data['block_content_field_revision']['revision_id']['relationship']['label'] = $this->t('Get the actual block content from a block content revision.');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\block_content\BlockContentTypeInterface;
|
||||
use Drupal\Core\Extension\ThemeHandlerInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class BlockContentController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* The custom block storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $blockContentStorage;
|
||||
|
||||
/**
|
||||
* The custom block type storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $blockContentTypeStorage;
|
||||
|
||||
/**
|
||||
* The theme handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ThemeHandlerInterface
|
||||
*/
|
||||
protected $themeHandler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('block_content'),
|
||||
$entity_manager->getStorage('block_content_type'),
|
||||
$container->get('theme_handler')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a BlockContent object.
|
||||
*
|
||||
* @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\Extension\ThemeHandlerInterface $theme_handler
|
||||
* The theme handler.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $block_content_storage, EntityStorageInterface $block_content_type_storage, ThemeHandlerInterface $theme_handler) {
|
||||
$this->blockContentStorage = $block_content_storage;
|
||||
$this->blockContentTypeStorage = $block_content_type_storage;
|
||||
$this->themeHandler = $theme_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays add custom block links for available types.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request object.
|
||||
*
|
||||
* @return array
|
||||
* A render array for a list of the custom block types that can be added or
|
||||
* if there is only one custom block type defined for the site, the function
|
||||
* returns the custom block add page for that custom block type.
|
||||
*/
|
||||
public function add(Request $request) {
|
||||
$types = $this->blockContentTypeStorage->loadMultiple();
|
||||
if ($types && count($types) == 1) {
|
||||
$type = reset($types);
|
||||
return $this->addForm($type, $request);
|
||||
}
|
||||
if (count($types) === 0) {
|
||||
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 ['#theme' => 'block_content_add_list', '#content' => $types];
|
||||
}
|
||||
|
||||
/**
|
||||
* Presents the custom block creation form.
|
||||
*
|
||||
* @param \Drupal\block_content\BlockContentTypeInterface $block_content_type
|
||||
* The custom block type to add.
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request object.
|
||||
*
|
||||
* @return array
|
||||
* A form array as expected by
|
||||
* \Drupal\Core\Render\RendererInterface::render().
|
||||
*/
|
||||
public function addForm(BlockContentTypeInterface $block_content_type, Request $request) {
|
||||
$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
|
||||
// newly created block in the given theme.
|
||||
$block->setTheme($theme);
|
||||
}
|
||||
return $this->entityFormBuilder()->getForm($block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the page title for this controller.
|
||||
*
|
||||
* @param \Drupal\block_content\BlockContentTypeInterface $block_content_type
|
||||
* The custom block type being added.
|
||||
*
|
||||
* @return string
|
||||
* The page title.
|
||||
*/
|
||||
public function getAddFormTitle(BlockContentTypeInterface $block_content_type) {
|
||||
return $this->t('Add %type custom block', ['%type' => $block_content_type->label()]);
|
||||
}
|
||||
|
||||
}
|
333
2017/web/core/modules/block_content/src/Entity/BlockContent.php
Normal file
333
2017/web/core/modules/block_content/src/Entity/BlockContent.php
Normal file
|
@ -0,0 +1,333 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Entity;
|
||||
|
||||
use Drupal\block_content\Access\RefinableDependentAccessTrait;
|
||||
use Drupal\Core\Entity\EditorialContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\block_content\BlockContentInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the custom block entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "block_content",
|
||||
* label = @Translation("Custom block"),
|
||||
* label_collection = @Translation("Custom blocks"),
|
||||
* label_singular = @Translation("custom block"),
|
||||
* label_plural = @Translation("custom blocks"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count custom block",
|
||||
* plural = "@count custom blocks",
|
||||
* ),
|
||||
* bundle_label = @Translation("Custom block type"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage",
|
||||
* "access" = "Drupal\block_content\BlockContentAccessControlHandler",
|
||||
* "list_builder" = "Drupal\block_content\BlockContentListBuilder",
|
||||
* "view_builder" = "Drupal\block_content\BlockContentViewBuilder",
|
||||
* "views_data" = "Drupal\block_content\BlockContentViewsData",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\block_content\BlockContentForm",
|
||||
* "edit" = "Drupal\block_content\BlockContentForm",
|
||||
* "delete" = "Drupal\block_content\Form\BlockContentDeleteForm",
|
||||
* "default" = "Drupal\block_content\BlockContentForm"
|
||||
* },
|
||||
* "translation" = "Drupal\block_content\BlockContentTranslationHandler"
|
||||
* },
|
||||
* admin_permission = "administer blocks",
|
||||
* 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",
|
||||
* "edit-form" = "/block/{block_content}",
|
||||
* "collection" = "/admin/structure/block/block-content",
|
||||
* "create" = "/block",
|
||||
* },
|
||||
* translatable = TRUE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "revision_id",
|
||||
* "bundle" = "type",
|
||||
* "label" = "info",
|
||||
* "langcode" = "langcode",
|
||||
* "uuid" = "uuid",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* revision_metadata_keys = {
|
||||
* "revision_user" = "revision_user",
|
||||
* "revision_created" = "revision_created",
|
||||
* "revision_log_message" = "revision_log"
|
||||
* },
|
||||
* bundle_entity_type = "block_content_type",
|
||||
* field_ui_base_route = "entity.block_content_type.edit_form",
|
||||
* render_cache = FALSE,
|
||||
* )
|
||||
*
|
||||
* Note that render caching of block_content entities is disabled because they
|
||||
* are always rendered as blocks, and blocks already have their own render
|
||||
* caching.
|
||||
* See https://www.drupal.org/node/2284917#comment-9132521 for more information.
|
||||
*/
|
||||
class BlockContent extends EditorialContentEntityBase implements BlockContentInterface {
|
||||
|
||||
use RefinableDependentAccessTrait;
|
||||
|
||||
/**
|
||||
* The theme the block is being created in.
|
||||
*
|
||||
* When creating a new custom block from the block library, the user is
|
||||
* redirected to the configure form for that block in the given theme. The
|
||||
* theme is stored against the block when the custom block add form is shown.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $theme;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDuplicate() {
|
||||
$duplicate = parent::createDuplicate();
|
||||
$duplicate->revision_id->value = NULL;
|
||||
$duplicate->id->value = NULL;
|
||||
return $duplicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setTheme($theme) {
|
||||
$this->theme = $theme;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTheme() {
|
||||
return $this->theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
|
||||
parent::postSave($storage, $update);
|
||||
if ($this->isReusable() || (isset($this->original) && $this->original->isReusable())) {
|
||||
static::invalidateBlockPluginCache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function postDelete(EntityStorageInterface $storage, array $entities) {
|
||||
parent::postDelete($storage, $entities);
|
||||
/** @var \Drupal\block_content\BlockContentInterface $block */
|
||||
foreach ($entities as $block) {
|
||||
if ($block->isReusable()) {
|
||||
// If any deleted blocks are reusable clear the block cache.
|
||||
static::invalidateBlockPluginCache();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstances() {
|
||||
return \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['plugin' => 'block_content:' . $this->uuid()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
|
||||
parent::preSaveRevision($storage, $record);
|
||||
|
||||
if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
|
||||
// If we are updating an existing block_content without adding a new
|
||||
// revision and the user did not supply a revision log, keep the existing
|
||||
// one.
|
||||
$record->revision_log = $this->original->getRevisionLogMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete() {
|
||||
foreach ($this->getInstances() as $instance) {
|
||||
$instance->delete();
|
||||
}
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['id']->setLabel(t('Custom block ID'))
|
||||
->setDescription(t('The custom block ID.'));
|
||||
|
||||
$fields['uuid']->setDescription(t('The custom block UUID.'));
|
||||
|
||||
$fields['revision_id']->setDescription(t('The revision ID.'));
|
||||
|
||||
$fields['langcode']->setDescription(t('The custom block language code.'));
|
||||
|
||||
$fields['type']->setLabel(t('Block type'))
|
||||
->setDescription(t('The block type.'));
|
||||
|
||||
$fields['revision_log']->setDescription(t('The log entry explaining the changes in this revision.'));
|
||||
|
||||
$fields['info'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Block description'))
|
||||
->setDescription(t('A brief description of your block.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setRequired(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -5,
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->addConstraint('UniqueField', []);
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
->setLabel(t('Changed'))
|
||||
->setDescription(t('The time that the custom block was last edited.'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['reusable'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Reusable'))
|
||||
->setDescription(t('A boolean indicating whether this block is reusable.'))
|
||||
->setTranslatable(FALSE)
|
||||
->setRevisionable(FALSE)
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionLog() {
|
||||
return $this->getRevisionLogMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setInfo($info) {
|
||||
$this->set('info', $info);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionLog($revision_log) {
|
||||
return $this->setRevisionLogMessage($revision_log);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionCreationTime() {
|
||||
return $this->get('revision_created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp) {
|
||||
$this->set('revision_created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionUser() {
|
||||
return $this->get('revision_user')->entity;
|
||||
}
|
||||
|
||||
public function setRevisionUser(UserInterface $account) {
|
||||
$this->set('revision_user', $account);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionUserId() {
|
||||
return $this->get('revision_user')->entity->id();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionUserId($user_id) {
|
||||
$this->set('revision_user', $user_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionLogMessage() {
|
||||
return $this->get('revision_log')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionLogMessage($revision_log_message) {
|
||||
$this->set('revision_log', $revision_log_message);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReusable() {
|
||||
return (bool) $this->get('reusable')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setReusable() {
|
||||
return $this->set('reusable', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setNonReusable() {
|
||||
return $this->set('reusable', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the block plugin cache after changes and deletions.
|
||||
*/
|
||||
protected static function invalidateBlockPluginCache() {
|
||||
// Invalidate the block cache to update custom block-based derivatives.
|
||||
\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
use Drupal\block_content\BlockContentTypeInterface;
|
||||
|
||||
/**
|
||||
* Defines the custom block type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "block_content_type",
|
||||
* label = @Translation("Custom block type"),
|
||||
* label_collection = @Translation("Custom block types"),
|
||||
* label_singular = @Translation("custom block type"),
|
||||
* label_plural = @Translation("custom block types"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count custom block type",
|
||||
* plural = "@count custom block types",
|
||||
* ),
|
||||
* label_collection = @Translation("Custom block library"),
|
||||
* handlers = {
|
||||
* "form" = {
|
||||
* "default" = "Drupal\block_content\BlockContentTypeForm",
|
||||
* "add" = "Drupal\block_content\BlockContentTypeForm",
|
||||
* "edit" = "Drupal\block_content\BlockContentTypeForm",
|
||||
* "delete" = "Drupal\block_content\Form\BlockContentTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider"
|
||||
* },
|
||||
* "list_builder" = "Drupal\block_content\BlockContentTypeListBuilder"
|
||||
* },
|
||||
* admin_permission = "administer blocks",
|
||||
* config_prefix = "type",
|
||||
* bundle_of = "block_content",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label"
|
||||
* },
|
||||
* links = {
|
||||
* "delete-form" = "/admin/structure/block/block-content/manage/{block_content_type}/delete",
|
||||
* "edit-form" = "/admin/structure/block/block-content/manage/{block_content_type}",
|
||||
* "collection" = "/admin/structure/block/block-content/types",
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
* "label",
|
||||
* "revision",
|
||||
* "description",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class BlockContentType extends ConfigEntityBundleBase implements BlockContentTypeInterface {
|
||||
|
||||
/**
|
||||
* The custom block type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The custom block type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* The default revision setting for custom blocks of this type.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The description of the block type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function shouldCreateNewRevision() {
|
||||
return $this->revision;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Event;
|
||||
|
||||
use Drupal\block_content\BlockContentInterface;
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Block content event to allow setting an access dependency.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentGetDependencyEvent extends Event {
|
||||
|
||||
/**
|
||||
* The block content entity.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $blockContent;
|
||||
|
||||
/**
|
||||
* The dependency.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessibleInterface
|
||||
*/
|
||||
protected $accessDependency;
|
||||
|
||||
/**
|
||||
* BlockContentGetDependencyEvent constructor.
|
||||
*
|
||||
* @param \Drupal\block_content\BlockContentInterface $blockContent
|
||||
* The block content entity.
|
||||
*/
|
||||
public function __construct(BlockContentInterface $blockContent) {
|
||||
$this->blockContent = $blockContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block content entity.
|
||||
*
|
||||
* @return \Drupal\block_content\BlockContentInterface
|
||||
* The block content entity.
|
||||
*/
|
||||
public function getBlockContentEntity() {
|
||||
return $this->blockContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the access dependency.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessibleInterface
|
||||
* The access dependency.
|
||||
*/
|
||||
public function getAccessDependency() {
|
||||
return $this->accessDependency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the access dependency.
|
||||
*
|
||||
* @param \Drupal\Core\Access\AccessibleInterface $access_dependency
|
||||
* The access dependency.
|
||||
*/
|
||||
public function setAccessDependency(AccessibleInterface $access_dependency) {
|
||||
$this->accessDependency = $access_dependency;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a confirmation form for deleting a custom block entity.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$instances = $this->entity->getInstances();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityDeleteForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a confirmation form for deleting a custom block type entity.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentTypeDeleteForm extends EntityDeleteForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$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.', ['%label' => $this->entity->label()]) . '</p>';
|
||||
$form['description'] = ['#markup' => $caption];
|
||||
return $form;
|
||||
}
|
||||
else {
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\Block;
|
||||
|
||||
use Drupal\block_content\BlockContentUuidLookup;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Routing\UrlGeneratorInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Defines a generic custom block type.
|
||||
*
|
||||
* @Block(
|
||||
* id = "block_content",
|
||||
* admin_label = @Translation("Custom block"),
|
||||
* category = @Translation("Custom"),
|
||||
* deriver = "Drupal\block_content\Plugin\Derivative\BlockContent"
|
||||
* )
|
||||
*/
|
||||
class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The Plugin Block Manager.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockManagerInterface
|
||||
*/
|
||||
protected $blockManager;
|
||||
|
||||
/**
|
||||
* The entity type manager service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The Drupal account to use for checking for access to block.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* The block content entity.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $blockContent;
|
||||
|
||||
/**
|
||||
* The URL generator.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\UrlGeneratorInterface
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
/**
|
||||
* The block content UUID lookup service.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentUuidLookup
|
||||
*/
|
||||
protected $uuidLookup;
|
||||
|
||||
/**
|
||||
* The entity display repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
|
||||
*/
|
||||
protected $entityDisplayRepository;
|
||||
|
||||
/**
|
||||
* Constructs a new BlockContentBlock.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
|
||||
* The Plugin Block Manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager service.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The account for which view access should be checked.
|
||||
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
|
||||
* The URL generator.
|
||||
* @param \Drupal\block_content\BlockContentUuidLookup $uuid_lookup
|
||||
* The block content UUID lookup service.
|
||||
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
|
||||
* The entity display repository.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockManagerInterface $block_manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $account, UrlGeneratorInterface $url_generator, BlockContentUuidLookup $uuid_lookup, EntityDisplayRepositoryInterface $entity_display_repository) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->blockManager = $block_manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->account = $account;
|
||||
$this->urlGenerator = $url_generator;
|
||||
$this->uuidLookup = $uuid_lookup;
|
||||
$this->entityDisplayRepository = $entity_display_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('plugin.manager.block'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('current_user'),
|
||||
$container->get('url_generator'),
|
||||
$container->get('block_content.uuid_lookup'),
|
||||
$container->get('entity_display.repository')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return [
|
||||
'status' => TRUE,
|
||||
'info' => '',
|
||||
'view_mode' => 'full',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\Block\BlockBase::blockForm().
|
||||
*
|
||||
* Adds body and description fields to the block configuration form.
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$block = $this->getEntity();
|
||||
if (!$block) {
|
||||
return $form;
|
||||
}
|
||||
$options = $this->entityDisplayRepository->getViewModeOptionsByBundle('block_content', $block->bundle());
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockSubmit($form, FormStateInterface $form_state) {
|
||||
// Invalidate the block cache to update custom block-based derivatives.
|
||||
$this->configuration['view_mode'] = $form_state->getValue('view_mode');
|
||||
$this->blockManager->clearCachedDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
if ($this->getEntity()) {
|
||||
return $this->getEntity()->access('view', $account, TRUE);
|
||||
}
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
if ($block = $this->getEntity()) {
|
||||
return $this->entityTypeManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
|
||||
}
|
||||
else {
|
||||
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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the block content entity of the block.
|
||||
*
|
||||
* @return \Drupal\block_content\BlockContentInterface|null
|
||||
* The block content entity.
|
||||
*/
|
||||
protected function getEntity() {
|
||||
if (!isset($this->blockContent)) {
|
||||
$uuid = $this->getDerivativeId();
|
||||
if ($id = $this->uuidLookup->get($uuid)) {
|
||||
$this->blockContent = $this->entityTypeManager->getStorage('block_content')->load($id);
|
||||
}
|
||||
}
|
||||
return $this->blockContent;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\Derivative;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Retrieves block plugin definitions for all custom blocks.
|
||||
*/
|
||||
class BlockContent extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
/**
|
||||
* The custom block storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $blockContentStorage;
|
||||
|
||||
/**
|
||||
* Constructs a BlockContent object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
|
||||
* The custom block storage.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $block_content_storage) {
|
||||
$this->blockContentStorage = $block_content_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('block_content')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$block_contents = $this->blockContentStorage->loadByProperties(['reusable' => TRUE]);
|
||||
// Reset the discovered definitions.
|
||||
$this->derivatives = [];
|
||||
/** @var $block_content \Drupal\block_content\Entity\BlockContent */
|
||||
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'] = [
|
||||
$block_content->getConfigDependencyName(),
|
||||
];
|
||||
}
|
||||
return parent::getDerivativeDefinitions($base_plugin_definition);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\Menu\LocalAction;
|
||||
|
||||
use Drupal\Core\Menu\LocalActionDefault;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Routing\UrlGeneratorTrait;
|
||||
|
||||
/**
|
||||
* Modifies the 'Add custom block' local action.
|
||||
*/
|
||||
class BlockContentAddLocalAction extends LocalActionDefault {
|
||||
use UrlGeneratorTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOptions(RouteMatchInterface $route_match) {
|
||||
$options = parent::getOptions($route_match);
|
||||
// If the route specifies a theme, append it to the query string.
|
||||
if ($theme = $route_match->getParameter('theme')) {
|
||||
$options['query']['theme'] = $theme;
|
||||
}
|
||||
// Adds a destination on custom block listing.
|
||||
if ($route_match->getRouteName() == 'entity.block_content.collection') {
|
||||
$options['query']['destination'] = $this->url('<current>');
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 block source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_box",
|
||||
* source_module = "block"
|
||||
* )
|
||||
*/
|
||||
class Box extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('boxes', 'b')
|
||||
->fields('b', ['bid', 'body', 'info', 'format']);
|
||||
$query->orderBy('b.bid');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
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.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['bid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\block_content\Plugin\migrate\source\d7\BlockCustomTranslation as D7BlockCustomTranslation;
|
||||
|
||||
/**
|
||||
* Gets Drupal 6 i18n custom block translations from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_box_translation",
|
||||
* source_module = "i18nblocks"
|
||||
* )
|
||||
*/
|
||||
class BoxTranslation extends D7BlockCustomTranslation {
|
||||
|
||||
/**
|
||||
* Drupal 6 table names.
|
||||
*/
|
||||
const CUSTOM_BLOCK_TABLE = 'boxes';
|
||||
const I18N_STRING_TABLE = 'i18n_strings';
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 7 custom block source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_block_custom",
|
||||
* source_module = "block"
|
||||
* )
|
||||
*/
|
||||
class BlockCustom extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('block_custom', 'b')->fields('b');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
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.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['bid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
use Drupal\content_translation\Plugin\migrate\source\I18nQueryTrait;
|
||||
|
||||
/**
|
||||
* Gets Drupal 7 custom block translation from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_block_custom_translation",
|
||||
* source_module = "block"
|
||||
* )
|
||||
*/
|
||||
class BlockCustomTranslation extends DrupalSqlBase {
|
||||
|
||||
use I18nQueryTrait;
|
||||
|
||||
/**
|
||||
* Drupal 7 table names.
|
||||
*/
|
||||
const CUSTOM_BLOCK_TABLE = 'block_custom';
|
||||
const I18N_STRING_TABLE = 'i18n_string';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// Build a query based on blockCustomTable table where each row has the
|
||||
// translation for only one property, either title or description. The
|
||||
// method prepareRow() is then used to obtain the translation for the
|
||||
// other property.
|
||||
$query = $this->select(static::CUSTOM_BLOCK_TABLE, 'b')
|
||||
->fields('b', ['bid', 'format', 'body'])
|
||||
->fields('i18n', ['property'])
|
||||
->fields('lt', ['lid', 'translation', 'language'])
|
||||
->orderBy('b.bid')
|
||||
->isNotNull('lt.lid');
|
||||
|
||||
// Use 'title' for the info field to match the property name in
|
||||
// i18nStringTable.
|
||||
$query->addField('b', 'info', 'title');
|
||||
|
||||
// Add in the property, which is either title or body. Cast the bid to text
|
||||
// so PostgreSQL can make the join.
|
||||
$query->leftJoin(static::I18N_STRING_TABLE, 'i18n', 'i18n.objectid = CAST(b.bid as CHAR(255))');
|
||||
$query->condition('i18n.type', 'block');
|
||||
|
||||
// Add in the translation for the property.
|
||||
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
parent::prepareRow($row);
|
||||
// Set the i18n string table for use in I18nQueryTrait.
|
||||
$this->i18nStringTable = static::I18N_STRING_TABLE;
|
||||
// Save the translation for this property.
|
||||
$property_in_row = $row->getSourceProperty('property');
|
||||
// Get the translation for the property not already in the row and save it
|
||||
// in the row.
|
||||
$property_not_in_row = ($property_in_row === 'title') ? 'body' : 'title';
|
||||
return $this->getPropertyNotInRowTranslation($row, $property_not_in_row, 'bid', $this->idMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'bid' => $this->t('The block numeric identifier.'),
|
||||
'format' => $this->t('Input format of the custom block/box content.'),
|
||||
'lid' => $this->t('i18n_string table id'),
|
||||
'language' => $this->t('Language for this field.'),
|
||||
'property' => $this->t('Block property'),
|
||||
'translation' => $this->t('The translation of the value of "property".'),
|
||||
'title' => $this->t('Block title.'),
|
||||
'title_translated' => $this->t('Block title translation.'),
|
||||
'body' => $this->t('Block body.'),
|
||||
'body_translated' => $this->t('Block body translation.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['bid']['type'] = 'integer';
|
||||
$ids['bid']['alias'] = 'b';
|
||||
$ids['language']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\views\area;
|
||||
|
||||
use Drupal\Core\Access\AccessManagerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\Plugin\views\area\AreaPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Defines an area plugin to display a block add link.
|
||||
*
|
||||
* @ingroup views_area_handlers
|
||||
*
|
||||
* @ViewsArea("block_content_listing_empty")
|
||||
*/
|
||||
class ListingEmpty extends AreaPluginBase {
|
||||
|
||||
/**
|
||||
* The access manager.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessManagerInterface
|
||||
*/
|
||||
protected $accessManager;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* Constructs a new ListingEmpty.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
|
||||
* The access manager.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, AccountInterface $current_user) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->accessManager = $access_manager;
|
||||
$this->currentUser = $current_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('access_manager'),
|
||||
$container->get('current_user')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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', [], $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 [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Plugin\views\wizard;
|
||||
|
||||
use Drupal\views\Plugin\views\wizard\WizardPluginBase;
|
||||
|
||||
/**
|
||||
* Used for creating 'block_content' views with the wizard.
|
||||
*
|
||||
* @ViewsWizard(
|
||||
* id = "block_content",
|
||||
* base_table = "block_content_field_data",
|
||||
* title = @Translation("Custom Block"),
|
||||
* )
|
||||
*/
|
||||
class BlockContent extends WizardPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters() {
|
||||
$filters = parent::getFilters();
|
||||
$filters['reusable'] = [
|
||||
'id' => 'reusable',
|
||||
'plugin_id' => 'boolean',
|
||||
'table' => $this->base_table,
|
||||
'field' => 'reusable',
|
||||
'value' => '1',
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'entity_field' => 'reusable',
|
||||
];
|
||||
return $filters;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Profile to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests\Views;
|
||||
|
||||
@trigger_error('\Drupal\block_content\Tests\Views\BlockContentTestBase is deprecated in 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Base class for all block_content tests.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\block_content\Functional\Views\BlockContentTestBase.
|
||||
*/
|
||||
abstract class BlockContentTestBase extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Admin user
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
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(['id' => 'basic']);
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||
|
||||
if ($import_test_views) {
|
||||
ViewTestData::createTestViews(get_class($this), ['block_content_test_views']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block.
|
||||
*
|
||||
* @param array $settings
|
||||
* (optional) An associative array of settings for the block_content, as
|
||||
* used in entity_create().
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent(array $settings = []) {
|
||||
$status = 0;
|
||||
$settings += [
|
||||
'info' => $this->randomMachineName(),
|
||||
'type' => 'basic',
|
||||
'langcode' => 'en',
|
||||
];
|
||||
if ($block_content = BlockContent::create($settings)) {
|
||||
$status = $block_content->save();
|
||||
}
|
||||
$this->assertEqual($status, SAVED_NEW, new FormattableMarkup('Created block content %info.', ['%info' => $block_content->label()]));
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block type (bundle).
|
||||
*
|
||||
* @param array $values
|
||||
* An array of settings to change from the defaults.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContentType
|
||||
* Created custom block type.
|
||||
*/
|
||||
protected function createBlockContentType(array $values = []) {
|
||||
// Find a non-existent random type name.
|
||||
if (!isset($values['id'])) {
|
||||
do {
|
||||
$id = strtolower($this->randomMachineName(8));
|
||||
} while (BlockContentType::load($id));
|
||||
}
|
||||
else {
|
||||
$id = $values['id'];
|
||||
}
|
||||
$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, new FormattableMarkup('Created block content type %bundle.', ['%bundle' => $bundle->id()]));
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{#
|
||||
/**
|
||||
* @file
|
||||
* Default theme implementation to present a list of custom block types.
|
||||
*
|
||||
* Available variables:
|
||||
* - types: A collection of all the available custom block types.
|
||||
* Each block type contains the following:
|
||||
* - link: A link to add a block of this type.
|
||||
* - description: A description of this custom block type.
|
||||
*
|
||||
* @see template_preprocess_block_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
<dd>{{ type.description }}</dd>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
|
||||
* upgrade path of https://www.drupal.org/project/drupal/issues/2976334.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Serialization\Yaml;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Override configuration for 'block_content' View with extra display with with
|
||||
// overridden filters.
|
||||
$config = Yaml::decode(file_get_contents(__DIR__ . '/views.view.block_content_2976334.yml'));
|
||||
$connection->update('config')
|
||||
->fields([
|
||||
'data' => serialize($config),
|
||||
])
|
||||
->condition('name', 'views.view.' . $config['id'])
|
||||
->execute();
|
602
2017/web/core/modules/block_content/tests/fixtures/update/views.view.block_content_2976334.yml
vendored
Normal file
602
2017/web/core/modules/block_content/tests/fixtures/update/views.view.block_content_2976334.yml
vendored
Normal file
|
@ -0,0 +1,602 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- user
|
||||
id: block_content
|
||||
label: 'Custom block library'
|
||||
module: views
|
||||
description: 'Find and manage custom blocks.'
|
||||
tag: default
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'administer blocks'
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: mini
|
||||
options:
|
||||
items_per_page: 50
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
tags:
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
override: true
|
||||
sticky: false
|
||||
caption: ''
|
||||
summary: ''
|
||||
description: ''
|
||||
columns:
|
||||
info: info
|
||||
type: type
|
||||
changed: changed
|
||||
operations: operations
|
||||
info:
|
||||
info:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
type:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
changed:
|
||||
sortable: true
|
||||
default_sort_order: desc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
operations:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
default: changed
|
||||
empty_table: true
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Block description'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings:
|
||||
link_to_entity: true
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
entity_type: null
|
||||
entity_field: info
|
||||
plugin_id: field
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Block type'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: target_id
|
||||
type: entity_reference_label
|
||||
settings:
|
||||
link: false
|
||||
group_column: target_id
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: field
|
||||
changed:
|
||||
id: changed
|
||||
table: block_content_field_data
|
||||
field: changed
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Updated
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
entity_type: block_content
|
||||
entity_field: changed
|
||||
type: timestamp
|
||||
settings:
|
||||
date_format: short
|
||||
custom_date_format: ''
|
||||
timezone: ''
|
||||
plugin_id: field
|
||||
operations:
|
||||
id: operations
|
||||
table: block_content
|
||||
field: operations
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Operations
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
destination: true
|
||||
entity_type: block_content
|
||||
plugin_id: entity_operations
|
||||
filters:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: info_op
|
||||
label: 'Block description'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: info_op
|
||||
identifier: info
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
plugin_id: string
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Block type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
sorts: { }
|
||||
title: 'Custom block library'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty:
|
||||
area_text_custom:
|
||||
id: area_text_custom
|
||||
table: views
|
||||
field: area_text_custom
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: true
|
||||
tokenize: false
|
||||
content: 'There are no custom blocks available.'
|
||||
plugin_id: text_custom
|
||||
block_content_listing_empty:
|
||||
admin_label: ''
|
||||
empty: true
|
||||
field: block_content_listing_empty
|
||||
group_type: group
|
||||
id: block_content_listing_empty
|
||||
label: ''
|
||||
relationship: none
|
||||
table: block_content
|
||||
plugin_id: block_content_listing_empty
|
||||
entity_type: block_content
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
max-age: 0
|
||||
tags: { }
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: admin/structure/block/block-content
|
||||
menu:
|
||||
type: tab
|
||||
title: 'Custom block library'
|
||||
description: ''
|
||||
parent: block.admin_display
|
||||
weight: 0
|
||||
context: '0'
|
||||
menu_name: admin
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
max-age: 0
|
||||
tags: { }
|
||||
page_2:
|
||||
display_plugin: page
|
||||
id: page_2
|
||||
display_title: 'Page 2'
|
||||
position: 2
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: extra-view-display
|
||||
filters:
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Block type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: 'contains'
|
||||
value: block2
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
placeholder: ''
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
plugin_id: string
|
||||
defaults:
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
tags: { }
|
|
@ -0,0 +1,8 @@
|
|||
name: "Custom Block module tests"
|
||||
type: module
|
||||
description: "Support module for custom block related testing."
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- drupal:block_content
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* A dummy module for testing custom block related hooks.
|
||||
*
|
||||
* This is a dummy module that implements custom block related hooks to test API
|
||||
* interaction with the block_content module.
|
||||
*/
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Implements hook_block_content_view().
|
||||
*/
|
||||
function block_content_test_block_content_view(array &$build, BlockContent $block_content, $view_mode) {
|
||||
// Add extra content.
|
||||
$build['extra_content'] = [
|
||||
'#markup' => '<blink>Yowser</blink>',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_content_presave().
|
||||
*/
|
||||
function block_content_test_block_content_presave(BlockContent $block_content) {
|
||||
if ($block_content->label() == 'testing_block_content_presave') {
|
||||
$block_content->setInfo($block_content->label() . '_presave');
|
||||
}
|
||||
// Determine changes.
|
||||
if (!empty($block_content->original) && $block_content->original->label() == 'test_changes') {
|
||||
if ($block_content->original->label() != $block_content->label()) {
|
||||
$block_content->setInfo($block_content->label() . '_presave');
|
||||
// Drupal 1.0 release.
|
||||
$block_content->changed = 979534800;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_content_update().
|
||||
*/
|
||||
function block_content_test_block_content_update(BlockContent $block_content) {
|
||||
// Determine changes on update.
|
||||
if (!empty($block_content->original) && $block_content->original->label() == 'test_changes') {
|
||||
if ($block_content->original->label() != $block_content->label()) {
|
||||
$block_content->setInfo($block_content->label() . '_update');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_content_insert().
|
||||
*
|
||||
* This tests saving a block_content on block_content insert.
|
||||
*
|
||||
* @see \Drupal\block_content\Tests\BlockContentSaveTest::testBlockContentSaveOnInsert()
|
||||
*/
|
||||
function block_content_test_block_content_insert(BlockContent $block_content) {
|
||||
// Set the block_content title to the block_content ID and save.
|
||||
if ($block_content->label() == 'new') {
|
||||
$block_content->setInfo('BlockContent ' . $block_content->id());
|
||||
$block_content->setNewRevision(FALSE);
|
||||
$block_content->save();
|
||||
}
|
||||
if ($block_content->label() == 'fail_creation') {
|
||||
throw new Exception('Test exception for rollback.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
block_content_test.block_content_view:
|
||||
path: '/block-content/{block_content}'
|
||||
defaults:
|
||||
_entity_view: 'block_content'
|
||||
requirements:
|
||||
_entity_access: 'block_content.view'
|
|
@ -0,0 +1,26 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
theme:
|
||||
- classy
|
||||
id: foobargorilla
|
||||
theme: classy
|
||||
region: content
|
||||
weight: null
|
||||
provider: null
|
||||
plugin: 'block_content:fb5e8434-3617-4a1d-a252-8273e95ec30e'
|
||||
settings:
|
||||
id: 'block_content:fb5e8434-3617-4a1d-a252-8273e95ec30e'
|
||||
label: 'Foobar Gorilla'
|
||||
provider: block_content
|
||||
label_display: visible
|
||||
status: true
|
||||
info: ''
|
||||
view_mode: default
|
||||
visibility:
|
||||
request_path:
|
||||
id: request_path
|
||||
pages: ''
|
||||
negate: false
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content_test\Plugin\EntityReferenceSelection;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
|
||||
|
||||
/**
|
||||
* Test EntityReferenceSelection with conditions on the 'reusable' field.
|
||||
*/
|
||||
class TestSelection extends DefaultSelection {
|
||||
|
||||
/**
|
||||
* The condition type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $conditionType;
|
||||
|
||||
/**
|
||||
* Whether to set the condition for reusable or non-reusable blocks.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isReusable;
|
||||
|
||||
/**
|
||||
* Sets the test mode.
|
||||
*
|
||||
* @param string $condition_type
|
||||
* The condition type.
|
||||
* @param bool $is_reusable
|
||||
* Whether to set the condition for reusable or non-reusable blocks.
|
||||
*/
|
||||
public function setTestMode($condition_type = NULL, $is_reusable = NULL) {
|
||||
$this->conditionType = $condition_type;
|
||||
$this->isReusable = $is_reusable;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
|
||||
$query = parent::buildEntityQuery($match, $match_operator);
|
||||
if ($this->conditionType) {
|
||||
/** @var \Drupal\Core\Database\Query\ConditionInterface $add_condition */
|
||||
$add_condition = NULL;
|
||||
switch ($this->conditionType) {
|
||||
case 'base':
|
||||
$add_condition = $query;
|
||||
break;
|
||||
|
||||
case 'group':
|
||||
$group = $query->andConditionGroup()
|
||||
->exists('type');
|
||||
$add_condition = $group;
|
||||
$query->condition($group);
|
||||
break;
|
||||
|
||||
case "nested_group":
|
||||
$query->exists('type');
|
||||
$sub_group = $query->andConditionGroup()
|
||||
->exists('type');
|
||||
$add_condition = $sub_group;
|
||||
$group = $query->andConditionGroup()
|
||||
->exists('type')
|
||||
->condition($sub_group);
|
||||
$query->condition($group);
|
||||
break;
|
||||
}
|
||||
if ($this->isReusable) {
|
||||
$add_condition->condition('reusable', 1);
|
||||
}
|
||||
else {
|
||||
$add_condition->condition('reusable', 0);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Block Content test views'
|
||||
type: module
|
||||
description: 'Provides default views for views block_content tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- drupal:block_content
|
||||
- drupal:views
|
|
@ -0,0 +1,234 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: test_block_content_redirect_destination
|
||||
label: 'Redirect destination'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: mini
|
||||
options:
|
||||
items_per_page: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: ‹‹
|
||||
next: ››
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
override: true
|
||||
sticky: false
|
||||
caption: ''
|
||||
summary: ''
|
||||
description: ''
|
||||
columns:
|
||||
info: info
|
||||
info:
|
||||
info:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
default: '-1'
|
||||
empty_table: false
|
||||
row:
|
||||
type: 'entity:block_content'
|
||||
fields:
|
||||
info:
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
id: info
|
||||
entity_type: null
|
||||
entity_field: info
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings: { }
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
operations:
|
||||
id: operations
|
||||
table: block_content
|
||||
field: operations
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Operations links'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
destination: true
|
||||
entity_type: block_content
|
||||
plugin_id: entity_operations
|
||||
filters: { }
|
||||
sorts: { }
|
||||
title: 'Redirect destination'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: /admin/content/redirect_destination
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
|
@ -0,0 +1,67 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: test_block_content_revision_id
|
||||
label: null
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_revision
|
||||
base_field: revision_id
|
||||
core: '8'
|
||||
display:
|
||||
default:
|
||||
display_options:
|
||||
relationships:
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_revision
|
||||
field: id
|
||||
required: true
|
||||
plugin_id: standard
|
||||
fields:
|
||||
revision_id:
|
||||
id: revision_id
|
||||
table: block_content_field_revision
|
||||
field: revision_id
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: revision_id
|
||||
id_1:
|
||||
id: id_1
|
||||
table: block_content_field_revision
|
||||
field: id
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_data
|
||||
field: id
|
||||
relationship: id
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
arguments:
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_revision
|
||||
field: id
|
||||
plugin_id: numeric
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
sorts:
|
||||
revision_id:
|
||||
id: revision_id
|
||||
table: block_content_field_revision
|
||||
field: revision_id
|
||||
order: ASC
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: revision_id
|
||||
display_plugin: default
|
||||
display_title: Master
|
||||
id: default
|
||||
position: 0
|
|
@ -0,0 +1,70 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: test_block_content_revision_revision_id
|
||||
label: null
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_revision
|
||||
base_field: revision_id
|
||||
core: '8'
|
||||
display:
|
||||
default:
|
||||
display_options:
|
||||
relationships:
|
||||
revision_id:
|
||||
id: revision_id
|
||||
table: block_content_field_revision
|
||||
field: revision_id
|
||||
required: true
|
||||
entity_type: block_content
|
||||
entity_field: revision_id
|
||||
plugin_id: standard
|
||||
fields:
|
||||
revision_id:
|
||||
id: revision_id
|
||||
table: block_content_field_revision
|
||||
field: revision_id
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: revision_id
|
||||
id_1:
|
||||
id: id_1
|
||||
table: block_content_field_revision
|
||||
field: id
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_data
|
||||
field: id
|
||||
relationship: revision_id
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
arguments:
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_revision
|
||||
field: id
|
||||
plugin_id: block_content_id
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
sorts:
|
||||
revision_id:
|
||||
id: revision_id
|
||||
table: block_content_field_revision
|
||||
field: revision_id
|
||||
order: ASC
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: revision_id
|
||||
display_extenders: { }
|
||||
display_plugin: default
|
||||
display_title: Master
|
||||
id: default
|
||||
position: 0
|
|
@ -0,0 +1,192 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: test_block_content_view
|
||||
label: test_block_content_view
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: null
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: full
|
||||
options:
|
||||
items_per_page: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
first: '« First'
|
||||
last: 'Last »'
|
||||
quantity: 9
|
||||
style:
|
||||
type: default
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Id
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
sorts:
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
plugin_id: standard
|
||||
title: test_block_content_view
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
display_extenders: { }
|
||||
arguments:
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: 'not found'
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: ''
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: false
|
||||
validate:
|
||||
type: none
|
||||
fail: 'not found'
|
||||
validate_options: { }
|
||||
glossary: false
|
||||
limit: 0
|
||||
case: none
|
||||
path_case: none
|
||||
transform_dash: false
|
||||
break_phrase: false
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: string
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: null
|
||||
display_options:
|
||||
path: test-block_content-view
|
||||
display_extenders: { }
|
|
@ -0,0 +1,339 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: test_field_filters
|
||||
label: 'Test field filters'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: none
|
||||
options:
|
||||
items_per_page: 0
|
||||
offset: 0
|
||||
style:
|
||||
type: default
|
||||
row:
|
||||
type: 'entity:block_content'
|
||||
options:
|
||||
relationship: none
|
||||
view_mode: default
|
||||
fields:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
label: ''
|
||||
alter:
|
||||
alter_text: false
|
||||
make_link: false
|
||||
absolute: false
|
||||
trim: false
|
||||
word_boundary: false
|
||||
ellipsis: false
|
||||
strip_tags: false
|
||||
html: false
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
exclude: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_alter_empty: true
|
||||
entity_type: block_content
|
||||
type: string
|
||||
settings:
|
||||
link_to_entity: true
|
||||
entity_field: title
|
||||
plugin_id: field
|
||||
filters:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: Paris
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
sorts:
|
||||
changed:
|
||||
id: changed
|
||||
table: block_content_field_data
|
||||
field: changed
|
||||
order: DESC
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
granularity: second
|
||||
plugin_id: date
|
||||
entity_type: block_content
|
||||
entity_field: changed
|
||||
title: 'Test field filters'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
rendering_language: '***LANGUAGE_entity_translation***'
|
||||
display_extenders: { }
|
||||
page_bf:
|
||||
display_plugin: page
|
||||
id: page_bf
|
||||
display_title: 'Body filter page'
|
||||
position: 1
|
||||
display_options:
|
||||
path: test-body-filter
|
||||
display_description: ''
|
||||
title: 'Test body filters'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
body_value:
|
||||
id: body_value
|
||||
table: block_content__body
|
||||
field: body_value
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: Comida
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
entity_type: block_content
|
||||
entity_field: body
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
display_extenders: { }
|
||||
page_bfp:
|
||||
display_plugin: page
|
||||
id: page_bfp
|
||||
display_title: 'Body filter page Paris'
|
||||
position: 1
|
||||
display_options:
|
||||
path: test-body-paris
|
||||
display_description: ''
|
||||
title: 'Test body filters'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
body_value:
|
||||
id: body_value
|
||||
table: block_content__body
|
||||
field: body_value
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: Paris
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
entity_type: block_content
|
||||
entity_field: body
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
display_extenders: { }
|
||||
page_if:
|
||||
display_plugin: page
|
||||
id: page_if
|
||||
display_title: 'Info filter page'
|
||||
position: 1
|
||||
display_options:
|
||||
path: test-info-filter
|
||||
display_description: ''
|
||||
title: 'Test info filter'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: Comida
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
display_extenders: { }
|
||||
page_ifp:
|
||||
display_plugin: page
|
||||
id: page_ifp
|
||||
display_title: 'Info filter page Paris'
|
||||
position: 1
|
||||
display_options:
|
||||
path: test-info-paris
|
||||
display_description: ''
|
||||
title: 'Test info filter'
|
||||
defaults:
|
||||
title: false
|
||||
display_extenders: { }
|
|
@ -0,0 +1,28 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
id: test_field_type
|
||||
label: ''
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: '8'
|
||||
display:
|
||||
default:
|
||||
display_options:
|
||||
fields:
|
||||
type:
|
||||
field: type
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
plugin_id: field
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
display_plugin: default
|
||||
display_title: Master
|
||||
id: default
|
||||
position: 0
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Tests the Custom Block entity's cache tags.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$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([
|
||||
'info' => 'Llama',
|
||||
'type' => 'basic',
|
||||
'body' => [
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Drupal\block_content\BlockContentAccessControlHandler::checkAccess()
|
||||
*/
|
||||
protected function getAccessCacheContextsForEntity(EntityInterface $entity) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Each comment must have a comment body, which always has a text format.
|
||||
*/
|
||||
protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) {
|
||||
return ['config:filter.format.plain_text'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the block is cached with the correct contexts and tags.
|
||||
*/
|
||||
public function testBlock() {
|
||||
$block = $this->drupalPlaceBlock('block_content:' . $this->entity->uuid());
|
||||
$build = $this->container->get('entity.manager')->getViewBuilder('block')->view($block, 'block');
|
||||
|
||||
// Render the block.
|
||||
// @todo The request stack manipulation won't be necessary once
|
||||
// https://www.drupal.org/node/2367555 is fixed and the
|
||||
// corresponding $request->isMethodCacheable() checks are removed from
|
||||
// Drupal\Core\Render\Renderer.
|
||||
$request_stack = $this->container->get('request_stack');
|
||||
$request_stack->push(new Request());
|
||||
$this->container->get('renderer')->renderRoot($build);
|
||||
$request_stack->pop();
|
||||
|
||||
// Expected keys, contexts, and tags for the block.
|
||||
// @see \Drupal\block\BlockViewBuilder::viewMultiple()
|
||||
$expected_block_cache_keys = ['entity_view', 'block', $block->id()];
|
||||
$expected_block_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
|
||||
$expected_block_cache_tags = Cache::mergeTags(['block_view', 'rendered'], $block->getCacheTags());
|
||||
$expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags, $block->getPlugin()->getCacheTags());
|
||||
|
||||
// Expected contexts and tags for the BlockContent entity.
|
||||
// @see \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults().
|
||||
$expected_entity_cache_contexts = ['theme'];
|
||||
$expected_entity_cache_tags = Cache::mergeTags(['block_content_view'], $this->entity->getCacheTags());
|
||||
$expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity));
|
||||
|
||||
// Verify that what was render cached matches the above expectations.
|
||||
$cid = $this->createCacheId($expected_block_cache_keys, $expected_block_cache_contexts);
|
||||
$redirected_cid = $this->createCacheId($expected_block_cache_keys, Cache::mergeContexts($expected_block_cache_contexts, $expected_entity_cache_contexts));
|
||||
$this->verifyRenderCache($cid, Cache::mergeTags($expected_block_cache_tags, $expected_entity_cache_tags), ($cid !== $redirected_cid) ? $redirected_cid : NULL);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Tests views contextual links on block content.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentContextualLinksTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'contextual',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests contextual links.
|
||||
*/
|
||||
public function testBlockContentContextualLinks() {
|
||||
$block_content = $this->createBlockContent();
|
||||
|
||||
$block = $this->placeBlock('block_content:' . $block_content->uuid());
|
||||
|
||||
$user = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'access contextual links',
|
||||
]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'block:block=' . $block->id() . ':langcode=en|block_content:block_content=' . $block_content->id() . ':');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,308 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Create a block and test saving it.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentCreationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* Enable dummy module that implements hook_block_insert() for exceptions and
|
||||
* field_ui to edit display settings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block_content_test', 'dblog', 'field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content display',
|
||||
];
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a "Basic page" block and verifies its consistency in the database.
|
||||
*/
|
||||
public function testBlockContentCreation() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a block.
|
||||
$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.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
]), '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 = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
// Check that attempting to create another block with the same value for
|
||||
// 'info' returns an error.
|
||||
$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.', [
|
||||
'%value' => $edit['info[0][value]'],
|
||||
]));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a "Basic page" block with multiple view modes.
|
||||
*/
|
||||
public function testBlockContentCreationMultipleViewModes() {
|
||||
// Add a new view mode and verify if it is selected as expected.
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer display modes']));
|
||||
$this->drupalGet('admin/structure/display-modes/view/add/block_content');
|
||||
$edit = [
|
||||
'id' => 'test_view_mode',
|
||||
'label' => 'Test View Mode',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a block.
|
||||
$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.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Save our block permanently
|
||||
$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 = [
|
||||
'display_modes_custom[test_view_mode]' => 1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $custom_view_mode, t('Save'));
|
||||
|
||||
// Go to the configure page and change the view mode.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
|
||||
// Test the available view mode options.
|
||||
$this->assertOption('edit-settings-view-mode', 'default', 'The default view mode is available.');
|
||||
$this->assertOption('edit-settings-view-mode', 'test_view_mode', 'The test view mode is available.');
|
||||
|
||||
$view_mode['settings[view_mode]'] = 'test_view_mode';
|
||||
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
|
||||
|
||||
// Check that the view mode setting is shown because more than one exists.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
|
||||
|
||||
// Change the view mode.
|
||||
$view_mode['region'] = 'content';
|
||||
$view_mode['settings[view_mode]'] = 'test_view_mode';
|
||||
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
|
||||
|
||||
// Go to the configure page and verify the view mode has changed.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]', 'test_view_mode', 'View mode changed to Test View Mode');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
// Check that attempting to create another block with the same value for
|
||||
// 'info' returns an error.
|
||||
$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.', [
|
||||
'%value' => $edit['info[0][value]'],
|
||||
]));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default custom block.
|
||||
*
|
||||
* Creates a custom block from defaults and ensures that the 'basic block'
|
||||
* type is being used.
|
||||
*/
|
||||
public function testDefaultBlockContentCreation() {
|
||||
$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.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Default Custom Block found in database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a transaction rolls back the failed creation.
|
||||
*/
|
||||
public function testFailedBlockCreation() {
|
||||
// Create a block.
|
||||
try {
|
||||
$this->createBlockContent('fail_creation');
|
||||
$this->fail('Expected exception has not been thrown.');
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->pass('Expected exception has been thrown.');
|
||||
}
|
||||
|
||||
if (Database::getConnection()->supportsTransactions()) {
|
||||
// Check that the block does not exist in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', ['id'])
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertFalse($id, 'Transactions supported, and block not found in database.');
|
||||
}
|
||||
else {
|
||||
// Check that the block exists in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', ['id'])
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertTrue($id, 'Transactions not supported, and block found in database.');
|
||||
|
||||
// Check that the failed rollback was logged.
|
||||
$records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
|
||||
$this->assertTrue(count($records) > 0, 'Transactions not supported, and rollback error logged to watchdog.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleting a block.
|
||||
*/
|
||||
public function testBlockDelete() {
|
||||
// Create a block.
|
||||
$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 = [
|
||||
'id' => mb_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'));
|
||||
|
||||
$block = BlockContent::load(1);
|
||||
|
||||
// Test getInstances method.
|
||||
$this->assertEqual(1, count($block->getInstances()));
|
||||
|
||||
// Navigate to home page.
|
||||
$this->drupalGet('');
|
||||
$this->assertText($body);
|
||||
|
||||
// Delete the block.
|
||||
$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, [], '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 = [];
|
||||
$edit2['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body2 = $this->randomMachineName(16);
|
||||
$edit2['body[0][value]'] = $body2;
|
||||
$this->drupalPostForm('block/add/basic', $edit2, t('Save'));
|
||||
|
||||
$this->assertNoRaw('Error message');
|
||||
|
||||
// Create another block with no instances, and test we don't get a
|
||||
// confirmation message about deleting instances.
|
||||
$edit3 = [];
|
||||
$edit3['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit3['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit3, t('Save'));
|
||||
|
||||
// Show the delete confirm form.
|
||||
$this->drupalGet('block/3/delete');
|
||||
$this->assertNoText('This will also remove');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that placed content blocks create a dependency in the block placement.
|
||||
*/
|
||||
public function testConfigDependencies() {
|
||||
$block = $this->createBlockContent();
|
||||
// Place the block.
|
||||
$block_placement_id = mb_strtolower($block->label());
|
||||
$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', [$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.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Tests the listing of custom blocks.
|
||||
*
|
||||
* Tests the fallback block content list when Views is disabled.
|
||||
*
|
||||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
* @see \Drupal\block_content\Tests\BlockContentListViewsTest
|
||||
*/
|
||||
class BlockContentListTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'config_translation'];
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'translate configuration']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
$this->assertTitle(t('Custom block library') . ' | Drupal');
|
||||
|
||||
// Test for the table.
|
||||
$element = $this->xpath('//div[@class="layout-content"]//table');
|
||||
$this->assertTrue($element, 'Configuration entity list table found.');
|
||||
|
||||
// Test the table header.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
|
||||
$this->assertEqual(count($elements), 2, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = [t('Block description'), t('Operations')];
|
||||
foreach ($elements as $key => $element) {
|
||||
$this->assertEqual($element->getText(), $expected_items[$key]);
|
||||
}
|
||||
|
||||
$label = 'Antelope';
|
||||
$new_label = 'Albatross';
|
||||
// Add a new entity using the operations link.
|
||||
$link_text = t('Add custom block');
|
||||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td', $label, 'Label found for added block.');
|
||||
|
||||
// Check the number of table row cells.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td');
|
||||
$this->assertEqual(count($elements), 2, 'Correct number of table row cells found.');
|
||||
// Check the contents of each row cell. The first cell contains the label,
|
||||
// the second contains the machine name, and the third contains the
|
||||
// operations list.
|
||||
$this->assertIdentical($elements[0]->getText(), $label);
|
||||
|
||||
// Edit the entity using the operations link.
|
||||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->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', ['%label' => $label]) . ' | Drupal'));
|
||||
$edit = ['info[0][value]' => $new_label];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
$this->fail('Did not find Albatross block in the database.');
|
||||
}
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td', $new_label, 'Label found for updated custom block.');
|
||||
|
||||
// Delete the added entity using the operations link.
|
||||
$this->assertLinkByHref('block/' . $block->id() . '/delete');
|
||||
$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?', ['%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).
|
||||
$this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
|
||||
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertText(t('There are no custom blocks yet.'));
|
||||
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Non-reusable block',
|
||||
'type' => 'basic',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertSession()->pageTextContains('There are no custom blocks yet.');
|
||||
// Confirm the non-reusable block is not on the page.
|
||||
$this->assertSession()->pageTextNotContains('Non-reusable block');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Tests the Views-powered listing of custom blocks.
|
||||
*
|
||||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
* @see \Drupal\block_content\Tests\BlockContentListTest
|
||||
*/
|
||||
class BlockContentListViewsTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'config_translation', 'views'];
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'translate configuration']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
$this->assertTitle(t('Custom block library') . ' | Drupal');
|
||||
|
||||
// Test for the exposed filters.
|
||||
$this->assertFieldByName('info');
|
||||
$this->assertFieldByName('type');
|
||||
|
||||
// Test for the table.
|
||||
$element = $this->xpath('//div[@class="layout-content"]//table');
|
||||
$this->assertTrue($element, 'Views table found.');
|
||||
|
||||
// Test the table header.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
|
||||
$this->assertEqual(count($elements), 4, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = ['Block description', 'Block type', 'Updated Sort ascending', 'Operations'];
|
||||
foreach ($elements as $key => $element) {
|
||||
if ($element->find('xpath', 'a')) {
|
||||
$this->assertIdentical(trim($element->find('xpath', 'a')->getText()), $expected_items[$key]);
|
||||
}
|
||||
else {
|
||||
$this->assertIdentical(trim($element->getText()), $expected_items[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$label = 'Antelope';
|
||||
$new_label = 'Albatross';
|
||||
// Add a new entity using the operations link.
|
||||
$link_text = t('Add custom block');
|
||||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td/a', $label, 'Label found for added block.');
|
||||
|
||||
// Check the number of table row cells.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td');
|
||||
$this->assertEqual(count($elements), 4, 'Correct number of table row cells found.');
|
||||
// Check the contents of each row cell. The first cell contains the label,
|
||||
// the second contains the machine name, and the third contains the
|
||||
// operations list.
|
||||
$this->assertIdentical($elements[0]->find('xpath', 'a')->getText(), $label);
|
||||
|
||||
// Edit the entity using the operations link.
|
||||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->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', ['%label' => $label]) . ' | Drupal'));
|
||||
$edit = ['info[0][value]' => $new_label];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
$this->fail('Did not find Albatross block in the database.');
|
||||
}
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td/a', $new_label, 'Label found for updated custom block.');
|
||||
|
||||
// Delete the added entity using the operations link.
|
||||
$this->assertLinkByHref('block/' . $block->id() . '/delete');
|
||||
$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?', ['%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).
|
||||
$this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
|
||||
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertText('There are no custom blocks available.');
|
||||
$this->assertLink('custom block');
|
||||
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Non-reusable block',
|
||||
'type' => 'basic',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertSession()->pageTextContains('There are no custom blocks available.');
|
||||
// Confirm the non-reusable block is not on the page.
|
||||
$this->assertSession()->pageTextNotContains('Non-reusable block');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Create a block and test block access by attempting to view the block.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentPageViewTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block_content_test'];
|
||||
|
||||
/**
|
||||
* Checks block edit and fallback functionality.
|
||||
*/
|
||||
public function testPageEdit() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$block = $this->createBlockContent();
|
||||
|
||||
// Attempt to view the block.
|
||||
$this->drupalGet('block-content/' . $block->id());
|
||||
|
||||
// Assert response was '200' and not '403 Access denied'.
|
||||
$this->assertResponse('200', 'User was able the view the block');
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertRaw(t('This block is broken or missing. You may be missing content or you might need to enable the original module.'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Create a block with revisions.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentRevisionsTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Stores blocks created during the test.
|
||||
* @var array
|
||||
*/
|
||||
protected $blocks;
|
||||
|
||||
/**
|
||||
* Stores log messages used during the test.
|
||||
* @var array
|
||||
*/
|
||||
protected $revisionLogs;
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
/** @var \Drupal\user\Entity\UserInterface $user */
|
||||
$user = User::load(1);
|
||||
|
||||
// Create initial block.
|
||||
$block = $this->createBlockContent('initial');
|
||||
|
||||
$blocks = [];
|
||||
$logs = [];
|
||||
|
||||
// Get original block.
|
||||
$blocks[] = $block->getRevisionId();
|
||||
$logs[] = '';
|
||||
|
||||
// Create three revisions.
|
||||
$revision_count = 3;
|
||||
for ($i = 0; $i < $revision_count; $i++) {
|
||||
$block->setNewRevision(TRUE);
|
||||
$block->setRevisionLogMessage($this->randomMachineName(32));
|
||||
$block->setRevisionUser($this->adminUser);
|
||||
$block->setRevisionCreationTime(REQUEST_TIME);
|
||||
$logs[] = $block->getRevisionLogMessage();
|
||||
$block->save();
|
||||
$blocks[] = $block->getRevisionId();
|
||||
}
|
||||
|
||||
$this->blocks = $blocks;
|
||||
$this->revisionLogs = $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks block revision related operations.
|
||||
*/
|
||||
public function testRevisions() {
|
||||
$blocks = $this->blocks;
|
||||
$logs = $this->revisionLogs;
|
||||
|
||||
foreach ($blocks as $delta => $revision_id) {
|
||||
// Confirm the correct revision text appears.
|
||||
/** @var \Drupal\block_content\BlockContentInterface $loaded */
|
||||
$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', [
|
||||
'@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.');
|
||||
$this->assertTrue(is_numeric($loaded->getRevisionCreationTime()), 'Revision time found.');
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm that this is the default revision.
|
||||
$this->assertTrue($loaded->isDefaultRevision(), 'Third block revision is the default one.');
|
||||
|
||||
// Make a new revision and set it to not be default.
|
||||
// This will create a new revision that is not "front facing".
|
||||
// Save this as a non-default revision.
|
||||
$loaded->setNewRevision();
|
||||
$loaded->isDefaultRevision(FALSE);
|
||||
$loaded->body = $this->randomMachineName(8);
|
||||
$loaded->save();
|
||||
|
||||
$this->drupalGet('block/' . $loaded->id());
|
||||
$this->assertNoText($loaded->body->value, 'Revision body text is not present on default version of block.');
|
||||
|
||||
// Verify that the non-default revision id is greater than the default
|
||||
// revision id.
|
||||
$default_revision = BlockContent::load($loaded->id());
|
||||
$this->assertTrue($loaded->getRevisionId() > $default_revision->getRevisionId(), 'Revision id is greater than default revision id.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Tests $block_content->save() for saving content.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentSaveTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block_content_test'];
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether custom block IDs are saved properly during an import.
|
||||
*/
|
||||
public function testImport() {
|
||||
// Custom block ID must be a number that is not in the database.
|
||||
$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 = [
|
||||
'info' => $info,
|
||||
'body' => ['value' => $this->randomMachineName(32)],
|
||||
'type' => 'basic',
|
||||
'id' => $test_id,
|
||||
];
|
||||
$block = BlockContent::create($block_array);
|
||||
$block->enforceIsNew(TRUE);
|
||||
$block->save();
|
||||
|
||||
// Verify that block_submit did not wipe the provided id.
|
||||
$this->assertEqual($block->id(), $test_id, 'Block imported using provide id');
|
||||
|
||||
// Test the import saved.
|
||||
$block_by_id = BlockContent::load($test_id);
|
||||
$this->assertTrue($block_by_id, 'Custom block load by block ID.');
|
||||
$this->assertIdentical($block_by_id->body->value, $block_array['body']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests determining changes in hook_block_presave().
|
||||
*
|
||||
* Verifies the static block load cache is cleared upon save.
|
||||
*/
|
||||
public function testDeterminingChanges() {
|
||||
// Initial creation.
|
||||
$block = $this->createBlockContent('test_changes');
|
||||
$this->assertEqual($block->getChangedTime(), REQUEST_TIME, 'Creating a block sets default "changed" timestamp.');
|
||||
|
||||
// Update the block without applying changes.
|
||||
$block->save();
|
||||
$this->assertEqual($block->label(), 'test_changes', 'No changes have been determined.');
|
||||
|
||||
// Apply changes.
|
||||
$block->setInfo('updated');
|
||||
$block->save();
|
||||
|
||||
// The hook implementations block_content_test_block_content_presave() and
|
||||
// block_content_test_block_content_update() determine changes and change
|
||||
// the title as well as programmatically set the 'changed' timestamp.
|
||||
$this->assertEqual($block->label(), 'updated_presave_update', 'Changes have been determined.');
|
||||
$this->assertEqual($block->getChangedTime(), 979534800, 'Saving a custom block uses "changed" timestamp set in presave hook.');
|
||||
|
||||
// Test the static block load cache to be cleared.
|
||||
$block = BlockContent::load($block->id());
|
||||
$this->assertEqual($block->label(), 'updated_presave', 'Static cache has been cleared.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving a block on block insert.
|
||||
*
|
||||
* This test ensures that a block has been fully saved when
|
||||
* hook_block_content_insert() is invoked, so that the block can be saved again
|
||||
* in a hook implementation without errors.
|
||||
*
|
||||
* @see block_test_block_insert()
|
||||
*/
|
||||
public function testBlockContentSaveOnInsert() {
|
||||
// block_content_test_block_content_insert() triggers a save on insert if the
|
||||
// title equals 'new'.
|
||||
$block = $this->createBlockContent('new');
|
||||
$this->assertEqual($block->label(), 'BlockContent ' . $block->id(), 'Custom block saved on block insert.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<?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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
|
||||
|
||||
/**
|
||||
* Tests the block content translation UI.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'language',
|
||||
'content_translation',
|
||||
'block',
|
||||
'field_ui',
|
||||
'block_content',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'session',
|
||||
'theme',
|
||||
'url.path',
|
||||
'url.query_args',
|
||||
'user.permissions',
|
||||
'user.roles:authenticated',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = 'block_content';
|
||||
$this->bundle = 'basic';
|
||||
$this->testLanguageSelector = FALSE;
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setupBundle() {
|
||||
// Create the basic bundle since it is provided by standard.
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $this->bundle,
|
||||
'label' => $this->bundle,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTranslatorPermissions() {
|
||||
return array_merge(parent::getTranslatorPermissions(), [
|
||||
'translate any entity',
|
||||
'access administration pages',
|
||||
'administer blocks',
|
||||
'administer block_content fields',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 bool|string $bundle
|
||||
* (optional) Bundle name. When no value is given, defaults to
|
||||
* $this->bundle. Defaults to FALSE.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent($title = FALSE, $bundle = FALSE) {
|
||||
$title = $title ?: $this->randomMachineName();
|
||||
$bundle = $bundle ?: $this->bundle;
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en',
|
||||
]);
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNewEntityValues($langcode) {
|
||||
return ['info' => mb_strtolower($this->randomMachineName())] + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit array containing the values to be posted.
|
||||
*/
|
||||
protected function getEditValues($values, $langcode, $new = FALSE) {
|
||||
$edit = parent::getEditValues($values, $langcode, $new);
|
||||
foreach ($edit as $property => $value) {
|
||||
if ($property == 'info') {
|
||||
$edit['info[0][value]'] = $value;
|
||||
unset($edit[$property]);
|
||||
}
|
||||
}
|
||||
return $edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestBasicTranslation() {
|
||||
parent::doTestBasicTranslation();
|
||||
|
||||
// Ensure that a block translation can be created using the same description
|
||||
// as in the original language.
|
||||
$default_langcode = $this->langcodes[0];
|
||||
$values = $this->getNewEntityValues($default_langcode);
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $storage->create(['type' => 'basic'] + $values);
|
||||
$entity->save();
|
||||
$entity->addTranslation('it', $values);
|
||||
|
||||
try {
|
||||
$message = 'Blocks can have translations with the same "info" value.';
|
||||
$entity->save();
|
||||
$this->pass($message);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->fail($message);
|
||||
}
|
||||
|
||||
// Check that the translate operation link is shown.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->assertLinkByHref('block/' . $entity->id() . '/translations');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no metadata is stored for a disabled bundle.
|
||||
*/
|
||||
public function testDisabledBundle() {
|
||||
// Create a bundle that does not have translation enabled.
|
||||
$disabled_bundle = $this->randomMachineName();
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $disabled_bundle,
|
||||
'label' => $disabled_bundle,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
// Create a block content for each bundle.
|
||||
$enabled_block_content = $this->createBlockContent();
|
||||
$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', [':id' => $enabled_block_content->id()])->fetchAll();
|
||||
$this->assertEqual(1, count($rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestTranslationEdit() {
|
||||
$storage = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId);
|
||||
$storage->resetCache([$this->entityId]);
|
||||
$entity = $storage->load($this->entityId);
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
// We only want to test the title for non-english translations.
|
||||
if ($langcode != 'en') {
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', [
|
||||
'@type' => $entity->bundle(),
|
||||
'@title' => $entity->getTranslation($langcode)->label(),
|
||||
'%language' => $languages[$langcode]->getName(),
|
||||
]);
|
||||
$this->assertRaw($title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Ensures that custom block type functions work correctly.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentTypeTest extends BlockContentTestBase {
|
||||
|
||||
use AssertBreadcrumbTrait;
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content fields',
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether or not to create an initial block type.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $autoCreateBasicBlockType = FALSE;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a block type programmatically and via a form.
|
||||
*/
|
||||
public function testBlockContentTypeCreation() {
|
||||
// Log in a test user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Test the page with no block-types.
|
||||
$this->drupalGet('block/add');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('You have not created any block types yet');
|
||||
$this->clickLink('block type creation page');
|
||||
|
||||
// Create a block type via the user interface.
|
||||
$edit = [
|
||||
'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.');
|
||||
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo');
|
||||
$this->assertTrue(isset($field_definitions['body']), 'Body field created when using the UI to create block content types.');
|
||||
|
||||
// Check that the block type was created in site default language.
|
||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||
$this->assertEqual($block_type->language()->getId(), $default_langcode);
|
||||
|
||||
// Create block types programmatically.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'basic');
|
||||
$this->assertTrue(isset($field_definitions['body']), "Body field for 'basic' block type created when using the testing API to create block content types.");
|
||||
|
||||
$this->createBlockContentType('other');
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types.");
|
||||
|
||||
$block_type = BlockContentType::load('other');
|
||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||
|
||||
$this->drupalGet('block/add/' . $block_type->id());
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests editing a block type using the UI.
|
||||
*/
|
||||
public function testBlockContentTypeEditing() {
|
||||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// We need two block types to prevent /block/add redirecting.
|
||||
$this->createBlockContentType('other');
|
||||
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
|
||||
|
||||
// Verify that title and body fields are displayed.
|
||||
$this->drupalGet('block/add/basic');
|
||||
$this->assertRaw('Block description', 'Block info field was found.');
|
||||
$this->assertNotEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was found.');
|
||||
|
||||
// Change the block type name.
|
||||
$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'));
|
||||
$front_page_path = Url::fromRoute('<front>')->toString();
|
||||
$this->assertBreadcrumb('admin/structure/block/block-content/manage/basic/fields', [
|
||||
$front_page_path => 'Home',
|
||||
'admin/structure/block' => 'Block layout',
|
||||
'admin/structure/block/block-content' => 'Custom block library',
|
||||
'admin/structure/block/block-content/manage/basic' => 'Edit Bar',
|
||||
]);
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
$this->drupalGet('block/add');
|
||||
$this->assertRaw('Bar', 'New name was displayed.');
|
||||
$this->clickLink('Bar');
|
||||
$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', [], t('Delete'));
|
||||
// Resave the settings for this type.
|
||||
$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->assertEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was not found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deleting a block type that still has content.
|
||||
*/
|
||||
public function testBlockContentTypeDeletion() {
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
// Create a block type programmatically.
|
||||
$type = $this->createBlockContentType('foo');
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Add a new block of this type.
|
||||
$block = $this->createBlockContent(FALSE, 'foo');
|
||||
// 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.', ['%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.');
|
||||
|
||||
// Delete the block.
|
||||
$block->delete();
|
||||
// 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?', ['%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.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that redirects work as expected when multiple block types exist.
|
||||
*/
|
||||
public function testsBlockContentAddTypes() {
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Create two block types programmatically.
|
||||
$type = $this->createBlockContentType('foo');
|
||||
$type = $this->createBlockContentType('bar');
|
||||
|
||||
// Get the custom block storage.
|
||||
$storage = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content');
|
||||
|
||||
// Install all themes.
|
||||
\Drupal::service('theme_handler')->install(['bartik', 'seven', 'stark']);
|
||||
$theme_settings = $this->config('system.theme');
|
||||
foreach (['bartik', 'seven', 'stark'] as $default_theme) {
|
||||
// Change the default theme.
|
||||
$theme_settings->set('default', $default_theme)->save();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// For each installed theme, go to its block page and test the redirects.
|
||||
foreach (['bartik', 'seven', 'stark'] as $theme) {
|
||||
// Test that adding a block from the 'place blocks' form sends you to the
|
||||
// block configure form.
|
||||
$path = $theme == $default_theme ? 'admin/structure/block' : "admin/structure/block/list/$theme";
|
||||
$this->drupalGet($path);
|
||||
$this->clickLink('Place block');
|
||||
$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 ? ['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 = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$block = reset($blocks);
|
||||
$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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test that adding a block from the 'custom blocks list' doesn't send you
|
||||
// to the block configure form.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
$this->clickLink('foo');
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$this->assertUrl(\Drupal::url('entity.block_content.collection', [], ['absolute' => TRUE]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Tests block content validation constraints.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentValidationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Tests the block content validation constraints.
|
||||
*/
|
||||
public function testValidation() {
|
||||
// Add a block.
|
||||
$description = $this->randomMachineName();
|
||||
$block = $this->createBlockContent($description, 'basic');
|
||||
// Validate the block.
|
||||
$violations = $block->validate();
|
||||
// Make sure we have no violations.
|
||||
$this->assertEqual(count($violations), 0);
|
||||
// Save the block.
|
||||
$block->save();
|
||||
|
||||
// Add another block with the same description.
|
||||
$block = $this->createBlockContent($description, 'basic');
|
||||
// Validate this block.
|
||||
$violations = $block->validate();
|
||||
// Make sure we have 1 violation.
|
||||
$this->assertEqual(count($violations), 1);
|
||||
// Make sure the violation is on the info property
|
||||
$this->assertEqual($violations[0]->getPropertyPath(), 'info');
|
||||
// Make sure the message is correct.
|
||||
$this->assertEqual($violations[0]->getMessage(), format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $block->label(),
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentResourceTestBase;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentHalJsonAnonTest extends BlockContentResourceTestBase {
|
||||
|
||||
use HalEntityNormalizationTrait;
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
$default_normalization = parent::getExpectedNormalizedEntity();
|
||||
|
||||
$normalization = $this->applyHalFieldNormalization($default_normalization);
|
||||
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/block/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/block_content/basic',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/block_content/basic',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeTags(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentHalJsonBasicAuthTest extends BlockContentHalJsonAnonTest {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentHalJsonCookieTest extends BlockContentHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentTypeHalJsonAnonTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentTypeHalJsonBasicAuthTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentTypeHalJsonCookieTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Create a block and test block edit functionality.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class PageEditTest extends BlockContentTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks block edit functionality.
|
||||
*/
|
||||
public function testPageEdit() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$title_key = 'info[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
// Create block to edit.
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = mb_strtolower($this->randomMachineName(8));
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityQuery('block_content')->condition('info', $edit['info[0][value]'])->execute();
|
||||
$block = BlockContent::load(reset($blocks));
|
||||
$this->assertTrue($block, 'Custom block found in database.');
|
||||
|
||||
// Load the edit page.
|
||||
$this->drupalGet('block/' . $block->id());
|
||||
$this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
|
||||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
|
||||
// Edit the content of the block.
|
||||
$edit = [];
|
||||
$edit[$title_key] = $this->randomMachineName(8);
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
// Stay on the current page, without reloading.
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Edit the same block, creating a new revision.
|
||||
$this->drupalGet("block/" . $block->id());
|
||||
$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([$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?', ['@label' => $revised_block->label()]));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentJsonAnonTest extends BlockContentResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentJsonBasicAuthTest extends BlockContentResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentJsonCookieTest extends BlockContentResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
/**
|
||||
* ResourceTestBase for BlockContent entity.
|
||||
*/
|
||||
abstract class BlockContentResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
use BcTimestampNormalizerUnixTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'block_content';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'changed' => NULL,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer blocks']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
if (!BlockContentType::load('basic')) {
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => TRUE,
|
||||
]);
|
||||
$block_content_type->save();
|
||||
block_content_add_body_field($block_content_type->id());
|
||||
}
|
||||
|
||||
// Create a "Llama" custom block.
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Llama',
|
||||
'type' => 'basic',
|
||||
'body' => [
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
])
|
||||
->setUnpublished();
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'id' => [
|
||||
[
|
||||
'value' => 1,
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $this->entity->uuid(),
|
||||
],
|
||||
],
|
||||
'langcode' => [
|
||||
[
|
||||
'value' => 'en',
|
||||
],
|
||||
],
|
||||
'reusable' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'type' => [
|
||||
[
|
||||
'target_id' => 'basic',
|
||||
'target_type' => 'block_content_type',
|
||||
'target_uuid' => BlockContentType::load('basic')->uuid(),
|
||||
],
|
||||
],
|
||||
'info' => [
|
||||
[
|
||||
'value' => 'Llama',
|
||||
],
|
||||
],
|
||||
'revision_log' => [],
|
||||
'changed' => [
|
||||
$this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
|
||||
],
|
||||
'revision_id' => [
|
||||
[
|
||||
'value' => 1,
|
||||
],
|
||||
],
|
||||
'revision_created' => [
|
||||
$this->formatExpectedTimestampItemValues((int) $this->entity->getRevisionCreationTime()),
|
||||
],
|
||||
'revision_user' => [],
|
||||
'revision_translation_affected' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'default_langcode' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'body' => [
|
||||
[
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
'summary' => NULL,
|
||||
'processed' => "<p>The name "llama" was adopted by European settlers from native Peruvians.</p>\n",
|
||||
],
|
||||
],
|
||||
'status' => [
|
||||
[
|
||||
'value' => FALSE,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return [
|
||||
'type' => [
|
||||
[
|
||||
'target_id' => 'basic',
|
||||
],
|
||||
],
|
||||
'info' => [
|
||||
[
|
||||
'value' => 'Dramallama',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessCacheability() {
|
||||
// @see \Drupal\block_content\BlockContentAccessControlHandler()
|
||||
return parent::getExpectedUnauthorizedAccessCacheability()
|
||||
->addCacheTags(['block_content:1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheTags() {
|
||||
return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:filter.format.plain_text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return Cache::mergeContexts(['url.site'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeJsonAnonTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeJsonBasicAuthTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeJsonCookieTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
|
||||
abstract class BlockContentTypeResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'block_content_type';
|
||||
|
||||
/**
|
||||
* @var \Drupal\block_content\Entity\BlockContentTypeInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer blocks']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'pascal',
|
||||
'label' => 'Pascal',
|
||||
'revision' => FALSE,
|
||||
'description' => 'Provides a competitive alternative to the "basic" type',
|
||||
]);
|
||||
|
||||
$block_content_type->save();
|
||||
|
||||
return $block_content_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'dependencies' => [],
|
||||
'description' => 'Provides a competitive alternative to the "basic" type',
|
||||
'id' => 'pascal',
|
||||
'label' => 'Pascal',
|
||||
'langcode' => 'en',
|
||||
'revision' => 0,
|
||||
'status' => TRUE,
|
||||
'uuid' => $this->entity->uuid(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeXmlAnonTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeXmlBasicAuthTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeXmlCookieTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentXmlAnonTest extends BlockContentResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue