Commit 95725e29 authored by webchick's avatar webchick

Issue #1920862 by martin107, Mixologic, cilefen, larowlan, xan.ps,...

Issue #1920862 by martin107, Mixologic, cilefen, larowlan, xan.ps, tim.plunkett | sun: Rename custom_block.module to block_content.module.
parent c4728bcc
......@@ -49,7 +49,7 @@ function block_help($route_name, Request $request) {
$output .= '<dt>' . t('Controlling visibility') . '</dt>';
$output .= '<dd>' . t('You can control the visibility of a block by restricting it to specific pages, content types, and/or roles by setting the appropriate options under <em>Visibility settings</em> of the block configuration.') . '</dd>';
$output .= '<dt>' . t('Adding custom blocks') . '</dt>';
$output .= '<dd>' . t('You can add custom blocks, if the the <em>Custom Block</em> module is enabled on the <a href="!extend">Extend page</a>. For more information, see the <a href="!customblock-help">Custom Block help page</a>.', array('!extend' => \Drupal::url('system.modules_list'), '!customblock-help' => \Drupal::url('help.page', array('name' => 'custom_block')))) . '</dd>';
$output .= '<dd>' . t('You can add custom blocks, if the the <em>Custom Block</em> module is enabled on the <a href="!extend">Extend page</a>. For more information, see the <a href="!blockcontent-help">Custom Block help page</a>.', array('!extend' => \Drupal::url('system.modules_list'), '!blockcontent-help' => \Drupal::url('help.page', array('name' => 'block_content')))) . '</dd>';
$output .= '</dl>';
return $output;
}
......
custom_block.block_edit:
title: 'Edit'
group: custom_block
route_name: 'custom_block.edit'
custom_block.block_delete:
title: 'Delete'
group: custom_block
route_name: 'custom_block.delete'
weight: 1
custom_block.list:
title: 'Custom block library'
route_name: custom_block.list
base_route: block.admin_display
custom_block.list_sub:
title: Blocks
route_name: custom_block.list
parent_id: custom_block.list
custom_block.type_list:
title: Types
route_name: custom_block.type_list
parent_id: custom_block.list
custom_block.edit:
title: Edit
route_name: custom_block.edit
base_route: custom_block.edit
custom_block.delete:
title: Delete
route_name: custom_block.delete
base_route: custom_block.edit
# Default tab for custom block type editing.
custom_block.type_edit:
title: 'Edit'
route_name: custom_block.type_edit
base_route: custom_block.type_edit
<?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 custom_block module.
*/
use Drupal\custom_block\Entity\CustomBlock;
/**
* Implements hook_custom_block_view().
*/
function custom_block_test_custom_block_view(array &$build, CustomBlock $custom_block, $view_mode) {
// Add extra content.
$build['extra_content'] = array(
'#markup' => '<blink>Yowser</blink>',
);
}
/**
* Implements hook_custom_block_presave().
*/
function custom_block_test_custom_block_presave(CustomBlock $custom_block) {
if ($custom_block->label() == 'testing_custom_block_presave') {
$custom_block->setInfo($custom_block->label() .'_presave');
}
// Determine changes.
if (!empty($custom_block->original) && $custom_block->original->label() == 'test_changes') {
if ($custom_block->original->label() != $custom_block->label()) {
$custom_block->setInfo($custom_block->label() .'_presave');
// Drupal 1.0 release.
$custom_block->changed = 979534800;
}
}
}
/**
* Implements hook_custom_block_update().
*/
function custom_block_test_custom_block_update(CustomBlock $custom_block) {
// Determine changes on update.
if (!empty($custom_block->original) && $custom_block->original->label() == 'test_changes') {
if ($custom_block->original->label() != $custom_block->label()) {
$custom_block->setInfo($custom_block->label() .'_update');
}
}
}
/**
* Implements hook_custom_block_insert().
*
* This tests saving a custom_block on custom_block insert.
*
* @see \Drupal\custom_block\Tests\CustomBlockSaveTest::testCustomBlockSaveOnInsert()
*/
function custom_block_test_custom_block_insert(CustomBlock $custom_block) {
// Set the custom_block title to the custom_block ID and save.
if ($custom_block->label() == 'new') {
$custom_block->setInfo('CustomBlock ' . $custom_block->id());
$custom_block->save();
}
if ($custom_block->label() == 'fail_creation') {
throw new Exception('Test exception for rollback.');
}
}
custom_block_test.custom_block_view:
path: '/custom-block/{custom_block}'
defaults:
_entity_view: 'custom_block'
requirements:
_entity_access: 'custom_block.view'
<?php
/**
* @file
* Contains \Drupal\custom_block\Tests\Menu\CustomBlockLocalTasksTest.
*/
namespace Drupal\custom_block\Tests\Menu;
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTest;
/**
* Tests existence of custom_block local tasks.
*
* @group Drupal
* @group Block
*/
class CustomBlockLocalTasksTest extends LocalTaskIntegrationTest {
public static function getInfo() {
return array(
'name' => 'Custom Block local tasks test',
'description' => 'Test custom_block local tasks.',
'group' => 'Block',
);
}
public function setUp() {
$this->directoryList = array(
'block' => 'core/modules/block',
'custom_block' => 'core/modules/block/custom_block',
);
parent::setUp();
}
/**
* Checks custom_block listing local tasks.
*
* @dataProvider getCustomBlockListingRoutes
*/
public function testCustomBlockListLocalTasks($route) {
//
$this->assertLocalTasks($route, array(
0 => array(
'block.admin_display',
'custom_block.list',
),
1 => array(
'custom_block.list_sub',
'custom_block.type_list',
)
));
}
/**
* Provides a list of routes to test.
*/
public function getCustomBlockListingRoutes() {
return array(
array('custom_block.list', 'custom_block.type_list'),
);
}
}
......@@ -18,7 +18,7 @@ class BlockConfigSchemaTest extends ConfigSchemaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('block', 'aggregator', 'book', 'custom_block', 'forum', 'statistics');
public static $modules = array('block', 'aggregator', 'book', 'block_content', 'forum', 'statistics');
/**
* The typed config manager.
......
block_content.block_edit:
title: 'Edit'
group: block_content
route_name: 'block_content.edit'
block_content.block_delete:
title: 'Delete'
group: block_content
route_name: 'block_content.delete'
weight: 1
......@@ -7,4 +7,4 @@ core: 8.x
dependencies:
- block
- text
configure: custom_block.list
configure: block_content.list
<?php
/**
* @file
* Install, update and uninstall functions for the custom block module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_schema().
*/
function block_content_schema() {
$schema = array();
$schema['block_content'] = array(
'description' => 'Stores contents of custom-made blocks.',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The block's {block_content}.id.",
),
'uuid' => array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'info' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Block description.',
),
// Defaults to NULL in order to avoid a brief period of potential
// deadlocks on the index.
'revision_id' => array(
'description' => 'The current {block_content_revision}.revision_id version identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
),
'type' => array(
'description' => 'The type of this custom block.',
'type' => 'varchar',
'length' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'not null' => TRUE,
'default' => '',
),
'changed' => array(
'description' => 'The Unix timestamp when the custom block was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'langcode' => array(
'description' => 'The {language}.langcode of this node.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
'indexes' => array(
'block_content_type' => array('type'),
),
'unique keys' => array(
'revision_id' => array('revision_id'),
'uuid' => array('uuid'),
'info' => array('info'),
),
'foreign keys' => array(
'block_content_revision' => array(
'table' => 'block_content_revision',
'columns' => array('revision_id' => 'revision_id'),
),
),
);
$schema['block_content_revision'] = array(
'description' => 'Stores contents of custom-made blocks.',
'fields' => array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => "The block's {block_content}.id.",
),
// Defaults to NULL in order to avoid a brief period of potential
// deadlocks on the index.
'revision_id' => array(
'description' => 'The current version identifier.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'revision_log' => array(
'description' => 'The log entry explaining the changes in this version.',
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
),
'info' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Block description.',
),
'changed' => array(
'description' => 'The Unix timestamp when the version was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('revision_id'),
);
return $schema;
}
drupal.custom_block:
drupal.block_content:
version: VERSION
js:
js/custom_block.js: {}
js/block_content.js: {}
dependencies:
- core/jquery
- core/drupal
......
custom_block_type_add:
route_name: custom_block.type_add
block_content_type_add:
route_name: block_content.type_add
title: 'Add custom block type'
appears_on:
- custom_block.type_list
- block_content.type_list
custom_block_add_action:
route_name: custom_block.add_page
block_content_add_action:
route_name: block_content.add_page
title: 'Add custom block'
appears_on:
- block.admin_display
- block.admin_display_theme
- custom_block.list
class: \Drupal\custom_block\Plugin\Menu\LocalAction\CustomBlockAddLocalAction
- block_content.list
class: \Drupal\block_content\Plugin\Menu\LocalAction\BlockContentAddLocalAction
block_content.list:
title: 'Custom block library'
route_name: block_content.list
base_route: block.admin_display
block_content.list_sub:
title: Blocks
route_name: block_content.list
parent_id: block_content.list
block_content.type_list:
title: Types
route_name: block_content.type_list
parent_id: block_content.list
block_content.edit:
title: Edit
route_name: block_content.edit
base_route: block_content.edit
block_content.delete:
title: Delete
route_name: block_content.delete
base_route: block_content.edit
# Default tab for custom block type editing.
block_content.type_edit:
title: 'Edit'
route_name: block_content.type_edit
base_route: block_content.type_edit
......@@ -12,26 +12,26 @@
/**
* Implements hook_help().
*/
function custom_block_help($route_name, Request $request) {
function block_content_help($route_name, Request $request) {
switch ($route_name) {
case 'help.page.custom_block':
case 'help.page.block_content':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Custom Block module allows you to create blocks of content, which can be placed in regions throughout the website. Custom blocks can have fields; see the <a href="!field-help">Field module help</a> for more information. Once created, custom blocks can be placed like blocks provided by other modules; see the <a href="!blocks">Block module help page</a> for details. For more information, see <a href="!online-help">the online documentation for the Custom Block module</a>.', array('!custom-blocks' => \Drupal::url('custom_block.list'), '!field-help' => \Drupal::url('help.page', array('name' => 'field')), '!blocks' => \Drupal::url('help.page', array('name' => 'block')), '!online-help' => 'https://drupal.org/documentation/modules/custom_block')) . '</p>';
$output .= '<p>' . t('The Custom Block module allows you to create blocks of content, which can be placed in regions throughout the website. Custom blocks can have fields; see the <a href="!field-help">Field module help</a> for more information. Once created, custom blocks can be placed like blocks provided by other modules; see the <a href="!blocks">Block module help page</a> for details. For more information, see <a href="!online-help">the online documentation for the Custom Block module</a>.', array('!block-content' => \Drupal::url('block_content.list'), '!field-help' => \Drupal::url('help.page', array('name' => 'field')), '!blocks' => \Drupal::url('help.page', array('name' => 'block')), '!online-help' => 'https://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 different custom block types, each with different fields and display settings, from the <a href="!types">Custom block types</a> page. The Custom block types page lists all of your created custom block types, and allows you to edit and manage them. For more information about managing fields and display settings, see the <a href="!field-ui">Field UI module help</a>.', array('!types' => \Drupal::url('custom_block.type_list'), '!field-ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create different custom block types, each with different fields and display settings, from the <a href="!types">Custom block types</a> page. The Custom block types page lists all of your created custom block types, and allows you to edit and manage them. For more information about managing fields and display settings, see the <a href="!field-ui">Field UI module help</a>.', array('!types' => \Drupal::url('block_content.type_list'), '!field-ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
$output .= '<dt>' . t('Creating custom blocks') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can <a href="!block-add">add custom blocks</a> of each of their defined custom block types. Created custom blocks are then listed on the <a href="!blocks">Blocks administration page</a>.', array('!blocks' => \Drupal::url('block.admin_display'), '!block-add' => \Drupal::url('custom_block.add_page'))) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can <a href="!block-add">add custom blocks</a> of each of their defined custom block types. Created custom blocks are then listed on the <a href="!blocks">Blocks administration page</a>.', array('!blocks' => \Drupal::url('block.admin_display'), '!block-add' => \Drupal::url('block_content.add_page'))) . '</dd>';
$output .= '</dl>';
return $output;
case 'custom_block.list':
case 'block_content.list':
$output = '<p>' . t('This page lists user-created blocks. These blocks are derived from block types. A block type can consist of different fields and display settings. From the block types tab you can manage these fields as well as create new block types.') . '</p>';
return $output;
case 'custom_block.type_list':
case 'block_content.type_list':
$output = '<p>' . t('This page lists block types. A block type can consist of different fields and display settings. From here you can manage these fields as well as create new block types.') . '</p>';
return $output;
......@@ -41,12 +41,12 @@ function custom_block_help($route_name, Request $request) {
/**
* Implements hook_theme().
*/
function custom_block_theme($existing, $type, $theme, $path) {
function block_content_theme($existing, $type, $theme, $path) {
return array(
'custom_block_add_list' => array(
'block_content_add_list' => array(
'variables' => array('content' => NULL),
'file' => 'custom_block.pages.inc',
'template' => 'custom-block-add-list',
'file' => 'block_content.pages.inc',
'template' => 'block-content-add-list',
),
);
}
......@@ -54,13 +54,13 @@ function custom_block_theme($existing, $type, $theme, $path) {
/**
* Implements hook_entity_type_alter().
*/
function custom_block_entity_type_alter(array &$entity_types) {
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['custom_block']->get('translation');
$translation['custom_block'] = TRUE;
$entity_types['custom_block']->set('translation', $translation);
$translation = $entity_types['block_content']->get('translation');
$translation['block_content'] = TRUE;
$entity_types['block_content']->set('translation', $translation);
}
}
......@@ -75,14 +75,14 @@ function custom_block_entity_type_alter(array &$entity_types) {
* @return array()
* Body field instance.
*/
function custom_block_add_body_field($block_type_id, $label = 'Body') {
function block_content_add_body_field($block_type_id, $label = 'Body') {
// Add or remove the body field, as needed.
$field = FieldConfig::loadByName('custom_block', 'body');
$instance = FieldInstanceConfig::loadByName('custom_block', $block_type_id, 'body');
$field = FieldConfig::loadByName('block_content', 'body');
$instance = FieldInstanceConfig::loadByName('block_content', $block_type_id, 'body');
if (empty($field)) {
$field = entity_create('field_config', array(
'name' => 'body',
'entity_type' => 'custom_block',
'entity_type' => 'block_content',
'type' => 'text_with_summary',
));
$field->save();
......@@ -97,14 +97,14 @@ function custom_block_add_body_field($block_type_id, $label = 'Body') {
$instance->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display('custom_block', $block_type_id, 'default')
entity_get_form_display('block_content', $block_type_id, 'default')
->setComponent('body', array(
'type' => 'text_textarea_with_summary',
))
->save();
// Assign display settings for 'default' view mode.
entity_get_display('custom_block', $block_type_id, 'default')
entity_get_display('block_content', $block_type_id, 'default')
->setComponent('body', array(
'label' => 'hidden',
'type' => 'text_default',
......
......@@ -6,27 +6,27 @@
*/
use Drupal\Component\Utility\Xss;
use Drupal\custom_block\Entity\CustomBlockType;
use Drupal\custom_block\Entity\CustomBlock;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\block_content\Entity\BlockContent;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Prepares variables for a custom block type creation list templates.
*
* Default template: custom-block-add-list.html.twig.
* Default template: block-content-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - content: An array of block types.
*
* @see custom_block_add_page()
* @see block_content_add_page()
*/
function template_preprocess_custom_block_add_list(&$variables) {
function template_preprocess_block_content_add_list(&$variables) {
$variables['types'] = array();
$query = \Drupal::request()->query->all();
foreach ($variables['content'] as $type) {
$variables['types'][$type->id()] = array(
'link' => \Drupal::l($type->label(), 'custom_block.add_form', array('custom_block_type' => $type->id()), array('query' => $query)),
'link' => \Drupal::l($type->label(), 'block_content.add_form', array('block_content_type' => $type->id()), array('query' => $query)),
'description' => Xss::filterAdmin($type->description),
'title' => $type->label(),
'localized_options' => array(
......
custom_block.type_list:
path: '/admin/structure/block/custom-blocks/types'
block_content.type_list:
path: '/admin/structure/block/block-content/types'
defaults:
_entity_list: 'custom_block_type'
_entity_list: 'block_content_type'
_title: 'Edit'
requirements:
_permission: 'administer blocks'
custom_block.add_page:
block_content.add_page:
path: '/block/add'
defaults:
_content: '\Drupal\custom_block\Controller\CustomBlockController::add'
_content: '\Drupal\block_content\Controller\BlockContentController::add'
_title: 'Add custom block'
options:
_admin_route: TRUE
requirements:
_permission: 'administer blocks'
custom_block.add_form:
path: '/block/add/{custom_block_type}'
block_content.add_form:
path: '/block/add/{block_content_type}'
defaults:
_content: '\Drupal\custom_block\Controller\CustomBlockController::addForm'
_title_callback: 'Drupal\custom_block\Controller\CustomBlockController::getAddFormTitle'
_content: '\Drupal\block_content\Controller\BlockContentController::addForm'
_title_callback: 'Drupal\block_content\Controller\BlockContentController::getAddFormTitle'
options:
_admin_route: TRUE
requirements:
_permission: 'administer blocks'
custom_block.type_delete:
path: '/admin/structure/block/custom-blocks/manage/{custom_block_type}/delete'
block_content.type_delete:
path: '/admin/structure/block/block-content/manage/{block_content_type}/delete'
defaults:
_entity_form: 'custom_block_type.delete'
_entity_form: 'block_content_type.delete'
_title: 'Delete'
requirements:
_entity_access: 'custom_block_type.delete'
_entity_access: 'block_content_type.delete'
options:
_admin_route: TRUE
custom_block.edit:
path: '/block/{custom_block}'
block_content.edit:
path: '/block/{block_content}'
defaults:
_entity_form: 'custom_block.edit'
_entity_form: 'block_content.edit'
options:
_admin_route: TRUE
requirements:
_entity_access: 'custom_block.update'
_entity_access: 'block_content.update'
custom_block.delete:
path: '/block/{custom_block}/delete'
block_content.delete:
path: '/block/{block_content}/delete'
defaults:
_entity_form: 'custom_block.delete'
_entity_form: 'block_content.delete'
_title: 'Delete'
options:
_admin_route: TRUE
requirements:
_entity_access: 'custom_block.delete'
_entity_access: 'block_content.delete'
custom_block.type_add:
path: '/admin/structure/block/custom-blocks/types/add'
block_content.type_add:
path: '/admin/structure/block/block-content/types/add'
defaults:
_entity_form: 'custom_block_type.add'
_entity_form: 'block_content_type.add'
_title: 'Add'
requirements:
_permission: 'administer blocks'
custom_block.type_edit:
path: '/admin/structure/block/custom-blocks/manage/{custom_block_type}'
block_content.type_edit:
path: '/admin/structure/block/block-content/manage/{block_content_type}'
defaults:
_entity_form: 'custom_block_type.edit'
_entity_form: 'block_content_type.edit'
_title: 'Edit'
requirements:
_entity_access: 'custom_block_type.update'
_entity_access: 'block_content_type.update'
custom_block.list:
path: '/admin/structure/block/custom-blocks'
block_content.list:
path: '/admin/structure/block/block-content'
defaults:
_title: 'Custom block library'
_entity_list: 'custom_block'
_entity_list: 'block_content'
requirements:
_permission: 'administer blocks'
id: custom_block.full
id: block_content.full
label: Full
status: false
cache: true
targetEntityType: custom_block
targetEntityType: block_content
dependencies:
module:
- custom_block