Issue #1920862 by martin107, Mixologic, cilefen, larowlan, xan.ps, tim.plunkett | sun: Rename custom_block.module to block_content.module.

8.0.x
webchick 2014-06-09 13:19:08 -07:00
parent c4728bcc15
commit 95725e29e9
70 changed files with 950 additions and 779 deletions

View File

@ -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;
}

View File

@ -1,8 +0,0 @@
id: custom_block.full
label: Full
status: false
cache: true
targetEntityType: custom_block
dependencies:
module:
- custom_block

View File

@ -1,10 +0,0 @@
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

View File

@ -1,14 +0,0 @@
custom_block_type_add:
route_name: custom_block.type_add
title: 'Add custom block type'
appears_on:
- custom_block.type_list
custom_block_add_action:
route_name: custom_block.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

View File

@ -1,27 +0,0 @@
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

View File

@ -1,80 +0,0 @@
custom_block.type_list:
path: '/admin/structure/block/custom-blocks/types'
defaults:
_entity_list: 'custom_block_type'
_title: 'Edit'
requirements:
_permission: 'administer blocks'
custom_block.add_page:
path: '/block/add'
defaults:
_content: '\Drupal\custom_block\Controller\CustomBlockController::add'
_title: 'Add custom block'
options:
_admin_route: TRUE
requirements:
_permission: 'administer blocks'
custom_block.add_form:
path: '/block/add/{custom_block_type}'
defaults:
_content: '\Drupal\custom_block\Controller\CustomBlockController::addForm'
_title_callback: 'Drupal\custom_block\Controller\CustomBlockController::getAddFormTitle'
options:
_admin_route: TRUE
requirements:
_permission: 'administer blocks'
custom_block.type_delete:
path: '/admin/structure/block/custom-blocks/manage/{custom_block_type}/delete'
defaults:
_entity_form: 'custom_block_type.delete'
_title: 'Delete'
requirements:
_entity_access: 'custom_block_type.delete'
options:
_admin_route: TRUE
custom_block.edit:
path: '/block/{custom_block}'
defaults:
_entity_form: 'custom_block.edit'
options:
_admin_route: TRUE
requirements:
_entity_access: 'custom_block.update'
custom_block.delete:
path: '/block/{custom_block}/delete'
defaults:
_entity_form: 'custom_block.delete'
_title: 'Delete'
options:
_admin_route: TRUE
requirements:
_entity_access: 'custom_block.delete'
custom_block.type_add:
path: '/admin/structure/block/custom-blocks/types/add'
defaults:
_entity_form: 'custom_block_type.add'
_title: 'Add'
requirements:
_permission: 'administer blocks'
custom_block.type_edit:
path: '/admin/structure/block/custom-blocks/manage/{custom_block_type}'
defaults:
_entity_form: 'custom_block_type.edit'
_title: 'Edit'
requirements:
_entity_access: 'custom_block_type.update'
custom_block.list:
path: '/admin/structure/block/custom-blocks'
defaults:
_title: 'Custom block library'
_entity_list: 'custom_block'
requirements:
_permission: 'administer blocks'

View File

@ -1,34 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\custom_block\CustomBlockStorage.
*/
namespace Drupal\custom_block;
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
/**
* Provides storage for the 'custom_block' entity type.
*/
class CustomBlockStorage extends ContentEntityDatabaseStorage {
/**
* {@inheritdoc}
*/
public function getSchema() {
$schema = parent::getSchema();
// Marking the respective fields as NOT NULL makes the indexes more
// performant.
$schema['custom_block']['fields']['info']['not null'] = TRUE;
$schema['custom_block']['unique keys'] += array(
'custom_block__info' => array('info'),
);
return $schema;
}
}

View File

@ -1,17 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\custom_block\Entity\CustomBlockTypeInterface.
*/
namespace Drupal\custom_block;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a custom block type entity.
*/
interface CustomBlockTypeInterface extends ConfigEntityInterface {
}

View File

@ -1,86 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\custom_block\Entity\CustomBlockType.
*/
namespace Drupal\custom_block\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\custom_block\CustomBlockTypeInterface;
/**
* Defines the custom block type entity.
*
* @ConfigEntityType(
* id = "custom_block_type",
* label = @Translation("Custom block type"),
* controllers = {
* "form" = {
* "default" = "Drupal\custom_block\CustomBlockTypeForm",
* "add" = "Drupal\custom_block\CustomBlockTypeForm",
* "edit" = "Drupal\custom_block\CustomBlockTypeForm",
* "delete" = "Drupal\custom_block\Form\CustomBlockTypeDeleteForm"
* },
* "list_builder" = "Drupal\custom_block\CustomBlockTypeListBuilder"
* },
* admin_permission = "administer blocks",
* config_prefix = "type",
* bundle_of = "custom_block",
* entity_keys = {
* "id" = "id",
* "label" = "label"
* },
* links = {
* "delete-form" = "custom_block.type_delete",
* "edit-form" = "custom_block.type_edit"
* }
* )
*/
class CustomBlockType extends ConfigEntityBundleBase implements CustomBlockTypeInterface {
/**
* The custom block type ID.
*
* @var string
*/
public $id;
/**
* The custom block type label.
*
* @var string
*/
public $label;
/**
* The default revision setting for custom blocks of this type.
*
* @var bool
*/
public $revision;
/**
* The description of the block type.
*
* @var string
*/
public $description;
/**
* {@inheritdoc}
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
if (!$update && !$this->isSyncing()) {
if (!$this->isSyncing()) {
custom_block_add_body_field($this->id);
}
}
}
}

View File

@ -1,28 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\custom_block\Plugin\Derivative\CustomBlock.
*/
namespace Drupal\custom_block\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DerivativeBase;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
/**
* Retrieves block plugin definitions for all custom blocks.
*/
class CustomBlock extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$custom_blocks = entity_load_multiple('custom_block');
foreach ($custom_blocks as $custom_block) {
$this->derivatives[$custom_block->uuid()] = $base_plugin_definition;
$this->derivatives[$custom_block->uuid()]['admin_label'] = $custom_block->label();
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}

View File

@ -1,68 +0,0 @@
<?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.');
}
}

View File

@ -1,6 +0,0 @@
custom_block_test.custom_block_view:
path: '/custom-block/{custom_block}'
defaults:
_entity_view: 'custom_block'
requirements:
_entity_access: 'custom_block.view'

View File

@ -1,64 +0,0 @@
<?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'),
);
}
}

View File

@ -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.

View File

@ -0,0 +1,10 @@
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

View File

@ -7,4 +7,4 @@ core: 8.x
dependencies:
- block
- text
configure: custom_block.list
configure: block_content.list

View File

@ -0,0 +1,125 @@
<?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;
}

View File

@ -1,7 +1,7 @@
drupal.custom_block:
drupal.block_content:
version: VERSION
js:
js/custom_block.js: {}
js/block_content.js: {}
dependencies:
- core/jquery
- core/drupal

View File

@ -0,0 +1,14 @@
block_content_type_add:
route_name: block_content.type_add
title: 'Add custom block type'
appears_on:
- block_content.type_list
block_content_add_action:
route_name: block_content.add_page
title: 'Add custom block'
appears_on:
- block.admin_display
- block.admin_display_theme
- block_content.list
class: \Drupal\block_content\Plugin\Menu\LocalAction\BlockContentAddLocalAction

View File

@ -0,0 +1,27 @@
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

View File

@ -12,26 +12,26 @@ use Drupal\field\Entity\FieldInstanceConfig;
/**
* 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',

View File

@ -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(

View File

@ -0,0 +1,80 @@
block_content.type_list:
path: '/admin/structure/block/block-content/types'
defaults:
_entity_list: 'block_content_type'
_title: 'Edit'
requirements:
_permission: 'administer blocks'
block_content.add_page:
path: '/block/add'
defaults:
_content: '\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:
_content: '\Drupal\block_content\Controller\BlockContentController::addForm'
_title_callback: 'Drupal\block_content\Controller\BlockContentController::getAddFormTitle'
options:
_admin_route: TRUE
requirements:
_permission: 'administer blocks'
block_content.type_delete:
path: '/admin/structure/block/block-content/manage/{block_content_type}/delete'
defaults:
_entity_form: 'block_content_type.delete'
_title: 'Delete'
requirements:
_entity_access: 'block_content_type.delete'
options:
_admin_route: TRUE
block_content.edit:
path: '/block/{block_content}'
defaults:
_entity_form: 'block_content.edit'
options:
_admin_route: TRUE
requirements:
_entity_access: 'block_content.update'
block_content.delete:
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.type_add:
path: '/admin/structure/block/block-content/types/add'
defaults:
_entity_form: 'block_content_type.add'
_title: 'Add'
requirements:
_permission: 'administer blocks'
block_content.type_edit:
path: '/admin/structure/block/block-content/manage/{block_content_type}'
defaults:
_entity_form: 'block_content_type.edit'
_title: 'Edit'
requirements:
_entity_access: 'block_content_type.update'
block_content.list:
path: '/admin/structure/block/block-content'
defaults:
_title: 'Custom block library'
_entity_list: 'block_content'
requirements:
_permission: 'administer blocks'

View File

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

View File

@ -1,6 +1,6 @@
# Schema for the configuration files of the Custom Block module.
custom_block.type.*:
block_content.type.*:
type: config_entity
label: 'Custom block type settings'
mapping:

View File

@ -1,16 +1,16 @@
/**
* @file
* Defines Javascript behaviors for the custom_block module.
* Defines Javascript behaviors for the block_content module.
*/
(function ($) {
"use strict";
Drupal.behaviors.customBlockDetailsSummaries = {
Drupal.behaviors.blockContentDetailsSummaries = {
attach: function (context) {
var $context = $(context);
$context.find('.custom-block-form-revision-information').drupalSetSummary(function (context) {
$context.find('.block-content-form-revision-information').drupalSetSummary(function (context) {
var $context = $(context);
var revisionCheckbox = $context.find('.form-item-revision input');
@ -25,7 +25,7 @@
return Drupal.t('No revision');
});
$context.find('fieldset.custom-block-translation-options').drupalSetSummary(function (context) {
$context.find('fieldset.block-content-translation-options').drupalSetSummary(function (context) {
var $context = $(context);
var translate;
var $checkbox = $context.find('.form-item-translation-translate input');

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockAccessController.
* Contains \Drupal\block_content\BlockContentAccessController.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityAccessController;
@ -14,7 +14,7 @@ use Drupal\Core\Session\AccountInterface;
/**
* Defines the access controller for the custom block entity type.
*/
class CustomBlockAccessController extends EntityAccessController {
class BlockContentAccessController extends EntityAccessController {
/**
* {@inheritdoc}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockForm.
* Contains \Drupal\block_content\BlockContentForm.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityForm;
@ -18,14 +18,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for the custom block edit forms.
*/
class CustomBlockForm extends ContentEntityForm {
class BlockContentForm extends ContentEntityForm {
/**
* The custom block storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $customBlockStorage;
protected $blockContentStorage;
/**
* The language manager.
@ -35,18 +35,18 @@ class CustomBlockForm extends ContentEntityForm {
protected $languageManager;
/**
* Constructs a CustomBlockForm object.
* Constructs a BlockContentForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityStorageInterface $custom_block_storage
* @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
* The custom block storage.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The language manager.
*/
public function __construct(EntityManagerInterface $entity_manager, EntityStorageInterface $custom_block_storage, LanguageManager $language_manager) {
public function __construct(EntityManagerInterface $entity_manager, EntityStorageInterface $block_content_storage, LanguageManager $language_manager) {
parent::__construct($entity_manager);
$this->customBlockStorage = $custom_block_storage;
$this->blockContentStorage = $block_content_storage;
$this->languageManager = $language_manager;
}
@ -57,7 +57,7 @@ class CustomBlockForm extends ContentEntityForm {
$entity_manager = $container->get('entity.manager');
return new static(
$entity_manager,
$entity_manager->getStorage('custom_block'),
$entity_manager->getStorage('block_content'),
$container->get('language_manager')
);
}
@ -67,13 +67,13 @@ class CustomBlockForm extends ContentEntityForm {
*
* Prepares the custom block object.
*
* Fills in a few default values, and then invokes hook_custom_block_prepare()
* Fills in a few default values, and then invokes hook_block_content_prepare()
* on all modules.
*/
protected function prepareEntity() {
$block = $this->entity;
// Set up default values, if required.
$block_type = entity_load('custom_block_type', $block->bundle());
$block_type = entity_load('block_content_type', $block->bundle());
if (!$block->isNew()) {
$block->setRevisionLog(NULL);
}
@ -97,7 +97,7 @@ class CustomBlockForm extends ContentEntityForm {
$form['#attributes']['class'][0] = drupal_html_class('block-' . $block->bundle() . '-form');
if ($this->moduleHandler->moduleExists('language')) {
$language_configuration = language_get_default_configuration('custom_block', $block->bundle());
$language_configuration = language_get_default_configuration('block_content', $block->bundle());
// Set the correct default language.
if ($block->isNew()) {
@ -128,10 +128,10 @@ class CustomBlockForm extends ContentEntityForm {
'#open' => $block->isNewRevision(),
'#group' => 'advanced',
'#attributes' => array(
'class' => array('custom-block-form-revision-information'),
'class' => array('block-content-form-revision-information'),
),
'#attached' => array(
'library' => array('custom_block/drupal.custom_block'),
'library' => array('block_content/drupal.block_content'),
),
'#weight' => 20,
'#access' => $block->isNewRevision() || $account->hasPermission('administer blocks'),
@ -195,7 +195,7 @@ class CustomBlockForm extends ContentEntityForm {
$insert = $block->isNew();
$block->save();
$watchdog_args = array('@type' => $block->bundle(), '%info' => $block->label());
$block_type = entity_load('custom_block_type', $block->bundle());
$block_type = entity_load('block_content_type', $block->bundle());
$t_args = array('@type' => $block_type->label(), '%info' => $block->label());
if ($insert) {
@ -217,13 +217,13 @@ class CustomBlockForm extends ContentEntityForm {
$form_state['redirect_route'] = array(
'route_name' => 'block.admin_add',
'route_parameters' => array(
'plugin_id' => 'custom_block:' . $block->uuid(),
'plugin_id' => 'block_content:' . $block->uuid(),
'theme' => $theme,
),
);
}
else {
$form_state['redirect_route']['route_name'] = 'custom_block.list';
$form_state['redirect_route']['route_name'] = 'block_content.list';
}
}
else {
@ -242,7 +242,7 @@ class CustomBlockForm extends ContentEntityForm {
*/
public function validateForm(array &$form, array &$form_state) {
if ($this->entity->isNew()) {
$exists = $this->customBlockStorage->loadByProperties(array('info' => $form_state['values']['info']));
$exists = $this->blockContentStorage->loadByProperties(array('info' => $form_state['values']['info']));
if (!empty($exists)) {
$this->setFormError('info', $form_state, $this->t('A block with description %name already exists.', array(
'%name' => $form_state['values']['info'][0]['value'],

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\Entity\CustomBlockInterface.
* Contains \Drupal\block_content\Entity\BlockContentInterface.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityChangedInterface;
/**
* Provides an interface defining a custom block entity.
*/
interface CustomBlockInterface extends ContentEntityInterface, EntityChangedInterface {
interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface {
/**
* Returns the block revision log message.
@ -29,7 +29,7 @@ interface CustomBlockInterface extends ContentEntityInterface, EntityChangedInte
* @param string $info
* The block description.
*
* @return \Drupal\custom_block\CustomBlockInterface
* @return \Drupal\block_content\BlockContentInterface
* The class instance that this method is called on.
*/
public function setInfo($info);
@ -40,7 +40,7 @@ interface CustomBlockInterface extends ContentEntityInterface, EntityChangedInte
* @param string $revision_log
* The revision log message.
*
* @return \Drupal\custom_block\CustomBlockInterface
* @return \Drupal\block_content\BlockContentInterface
* The class instance that this method is called on.
*/
public function setRevisionLog($revision_log);
@ -55,7 +55,7 @@ interface CustomBlockInterface extends ContentEntityInterface, EntityChangedInte
* @param string $theme
* The theme name.
*
* @return \Drupal\custom_block\CustomBlockInterface
* @return \Drupal\block_content\BlockContentInterface
* The class instance that this method is called on.
*/
public function setTheme($theme);

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockListBuilder.
* Contains \Drupal\block_content\BlockContentListBuilder.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
@ -13,9 +13,9 @@ use Drupal\Core\Entity\EntityListBuilder;
/**
* Defines a class to build a listing of custom block entities.
*
* @see \Drupal\custom_block\Entity\CustomBlock
* @see \Drupal\block_content\Entity\BlockContent
*/
class CustomBlockListBuilder extends EntityListBuilder {
class BlockContentListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
@ -39,7 +39,7 @@ class CustomBlockListBuilder extends EntityListBuilder {
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['query']['destination'] = 'admin/structure/block/custom-blocks';
$operations['edit']['query']['destination'] = 'admin/structure/block/block-content';
}
return $operations;
}

View File

@ -0,0 +1,34 @@
<?php
/**
* @file
* Contains \Drupal\block_content\BlockContentStorage.
*/
namespace Drupal\block_content;
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
/**
* Provides storage for the 'block_content' entity type.
*/
class BlockContentStorage extends ContentEntityDatabaseStorage {
/**
* {@inheritdoc}
*/
public function getSchema() {
$schema = parent::getSchema();
// Marking the respective fields as NOT NULL makes the indexes more
// performant.
$schema['block_content']['fields']['info']['not null'] = TRUE;
$schema['block_content']['unique keys'] += array(
'block_content__info' => array('info'),
);
return $schema;
}
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockTranslationHandler.
* Contains \Drupal\block_content\BlockContentTranslationHandler.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\ContentTranslationHandler;
@ -13,7 +13,7 @@ use Drupal\content_translation\ContentTranslationHandler;
/**
* Defines the translation handler for custom blocks.
*/
class CustomBlockTranslationHandler extends ContentTranslationHandler {
class BlockContentTranslationHandler extends ContentTranslationHandler {
/**
* {@inheritdoc}
@ -26,7 +26,7 @@ class CustomBlockTranslationHandler extends ContentTranslationHandler {
'#group' => 'additional_settings',
'#weight' => 100,
'#attributes' => array(
'class' => array('custom-block-translation-options'),
'class' => array('block-content-translation-options'),
),
);
}
@ -36,7 +36,7 @@ class CustomBlockTranslationHandler extends ContentTranslationHandler {
* {@inheritdoc}
*/
protected function entityFormTitle(EntityInterface $entity) {
$block_type = entity_load('custom_block_type', $entity->bundle());
$block_type = entity_load('block_content_type', $entity->bundle());
return t('<em>Edit @type</em> @title', array('@type' => $block_type->label(), '@title' => $entity->label()));
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockTypeForm.
* Contains \Drupal\block_content\BlockContentTypeForm.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeInterface;
@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
/**
* Base form for category edit forms.
*/
class CustomBlockTypeForm extends EntityForm {
class BlockContentTypeForm extends EntityForm {
/**
* Overrides \Drupal\Core\Entity\EntityForm::form().
@ -35,7 +35,7 @@ class CustomBlockTypeForm extends EntityForm {
'#type' => 'machine_name',
'#default_value' => $block_type->id(),
'#machine_name' => array(
'exists' => '\Drupal\custom_block\Entity\CustomBlockType::load',
'exists' => '\Drupal\block_content\Entity\BlockContentType::load',
),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#disabled' => !$block_type->isNew(),
@ -62,11 +62,11 @@ class CustomBlockTypeForm extends EntityForm {
'#group' => 'additional_settings',
);
$language_configuration = language_get_default_configuration('custom_block', $block_type->id());
$language_configuration = language_get_default_configuration('block_content', $block_type->id());
$form['language']['language_configuration'] = array(
'#type' => 'language_configuration',
'#entity_information' => array(
'entity_type' => 'custom_block',
'entity_type' => 'block_content',
'bundle' => $block_type->id(),
),
'#default_value' => $language_configuration,
@ -94,14 +94,14 @@ class CustomBlockTypeForm extends EntityForm {
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label())));
watchdog('custom_block', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
watchdog('block_content', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
}
else {
drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label())));
watchdog('custom_block', 'Custom block type %label has been added.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
watchdog('block_content', 'Custom block type %label has been added.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
}
$form_state['redirect_route']['route_name'] = 'custom_block.type_list';
$form_state['redirect_route']['route_name'] = 'block_content.type_list';
}
}

View File

@ -0,0 +1,17 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Entity\BlockContentTypeInterface.
*/
namespace Drupal\block_content;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a custom block type entity.
*/
interface BlockContentTypeInterface extends ConfigEntityInterface {
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockTypeListBuilder.
* Contains \Drupal\block_content\BlockContentTypeListBuilder.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
@ -14,9 +14,9 @@ use Drupal\Core\Entity\EntityInterface;
/**
* Defines a class to build a listing of custom block type entities.
*
* @see \Drupal\custom_block\Entity\CustomBlockType
* @see \Drupal\block_content\Entity\BlockContentType
*/
class CustomBlockTypeListBuilder extends ConfigEntityListBuilder {
class BlockContentTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\CustomBlockViewBuilder.
* Contains \Drupal\block_content\BlockContentViewBuilder.
*/
namespace Drupal\custom_block;
namespace Drupal\block_content;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityViewBuilder;
/**
* Render controller for custom blocks.
*/
class CustomBlockViewBuilder extends EntityViewBuilder {
class BlockContentViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
@ -23,8 +23,8 @@ class CustomBlockViewBuilder extends EntityViewBuilder {
parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
// Add contextual links for this custom block.
if (!$entity->isNew() && $view_mode == 'full') {
$build['#contextual_links']['custom_block'] = array(
'route_parameters' => array('custom_block' => $entity->id()),
$build['#contextual_links']['block_content'] = array(
'route_parameters' => array('block_content' => $entity->id()),
'metadata' => array('changed' => $entity->getChangedTime()),
);
}

View File

@ -2,33 +2,33 @@
/**
* @file
* Contains \Drupal\custom_block\Controller\CustomBlockController
* Contains \Drupal\block_content\Controller\BlockContentController
*/
namespace Drupal\custom_block\Controller;
namespace Drupal\block_content\Controller;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\custom_block\CustomBlockTypeInterface;
use Drupal\block_content\BlockContentTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class CustomBlockController extends ControllerBase {
class BlockContentController extends ControllerBase {
/**
* The custom block storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $customBlockStorage;
protected $blockContentStorage;
/**
* The custom block type storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $customBlockTypeStorage;
protected $blockContentTypeStorage;
/**
* {@inheritdoc}
@ -36,22 +36,22 @@ class CustomBlockController extends ControllerBase {
public static function create(ContainerInterface $container) {
$entity_manager = $container->get('entity.manager');
return new static(
$entity_manager->getStorage('custom_block'),
$entity_manager->getStorage('custom_block_type')
$entity_manager->getStorage('block_content'),
$entity_manager->getStorage('block_content_type')
);
}
/**
* Constructs a CustomBlock object.
* Constructs a BlockContent object.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $custom_block_storage
* @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
* The custom block storage.
* @param \Drupal\Core\Entity\EntityStorageInterface $custom_block_type_storage
* @param \Drupal\Core\Entity\EntityStorageInterface $block_content_type_storage
* The custom block type storage.
*/
public function __construct(EntityStorageInterface $custom_block_storage, EntityStorageInterface $custom_block_type_storage) {
$this->customBlockStorage = $custom_block_storage;
$this->customBlockTypeStorage = $custom_block_type_storage;
public function __construct(EntityStorageInterface $block_content_storage, EntityStorageInterface $block_content_type_storage) {
$this->blockContentStorage = $block_content_storage;
$this->blockContentTypeStorage = $block_content_type_storage;
}
/**
@ -66,19 +66,19 @@ class CustomBlockController extends ControllerBase {
* returns the custom block add page for that custom block type.
*/
public function add(Request $request) {
$types = $this->customBlockTypeStorage->loadMultiple();
$types = $this->blockContentTypeStorage->loadMultiple();
if ($types && count($types) == 1) {
$type = reset($types);
return $this->addForm($type, $request);
}
return array('#theme' => 'custom_block_add_list', '#content' => $types);
return array('#theme' => 'block_content_add_list', '#content' => $types);
}
/**
* Presents the custom block creation form.
*
* @param \Drupal\custom_block\CustomBlockTypeInterface $custom_block_type
* @param \Drupal\block_content\BlockContentTypeInterface $block_content_type
* The custom block type to add.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
@ -86,9 +86,9 @@ class CustomBlockController extends ControllerBase {
* @return array
* A form array as expected by drupal_render().
*/
public function addForm(CustomBlockTypeInterface $custom_block_type, Request $request) {
$block = $this->customBlockStorage->create(array(
'type' => $custom_block_type->id()
public function addForm(BlockContentTypeInterface $block_content_type, Request $request) {
$block = $this->blockContentStorage->create(array(
'type' => $block_content_type->id()
));
if (($theme = $request->query->get('theme')) && in_array($theme, array_keys(list_themes()))) {
// We have navigated to this page from the block library and will keep track
@ -102,14 +102,14 @@ class CustomBlockController extends ControllerBase {
/**
* Provides the page title for this controller.
*
* @param \Drupal\custom_block\CustomBlockTypeInterface $custom_block_type
* @param \Drupal\block_content\BlockContentTypeInterface $block_content_type
* The custom block type being added.
*
* @return string
* The page title.
*/
public function getAddFormTitle(CustomBlockTypeInterface $custom_block_type) {
return $this->t('Add %type custom block', array('%type' => $custom_block_type->label()));
public function getAddFormTitle(BlockContentTypeInterface $block_content_type) {
return $this->t('Add %type custom block', array('%type' => $block_content_type->label()));
}
}

View File

@ -2,45 +2,45 @@
/**
* @file
* Contains \Drupal\custom_block\Entity\CustomBlock.
* Contains \Drupal\block_content\Entity\BlockContent.
*/
namespace Drupal\custom_block\Entity;
namespace Drupal\block_content\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\custom_block\CustomBlockInterface;
use Drupal\block_content\BlockContentInterface;
/**
* Defines the custom block entity class.
*
* @ContentEntityType(
* id = "custom_block",
* id = "block_content",
* label = @Translation("Custom Block"),
* bundle_label = @Translation("Custom Block type"),
* controllers = {
* "storage" = "Drupal\custom_block\CustomBlockStorage",
* "access" = "Drupal\custom_block\CustomBlockAccessController",
* "list_builder" = "Drupal\custom_block\CustomBlockListBuilder",
* "view_builder" = "Drupal\custom_block\CustomBlockViewBuilder",
* "storage" = "Drupal\block_content\BlockContentStorage",
* "access" = "Drupal\block_content\BlockContentAccessController",
* "list_builder" = "Drupal\block_content\BlockContentListBuilder",
* "view_builder" = "Drupal\block_content\BlockContentViewBuilder",
* "form" = {
* "add" = "Drupal\custom_block\CustomBlockForm",
* "edit" = "Drupal\custom_block\CustomBlockForm",
* "delete" = "Drupal\custom_block\Form\CustomBlockDeleteForm",
* "default" = "Drupal\custom_block\CustomBlockForm"
* "add" = "Drupal\block_content\BlockContentForm",
* "edit" = "Drupal\block_content\BlockContentForm",
* "delete" = "Drupal\block_content\Form\BlockContentDeleteForm",
* "default" = "Drupal\block_content\BlockContentForm"
* },
* "translation" = "Drupal\custom_block\CustomBlockTranslationHandler"
* "translation" = "Drupal\block_content\BlockContentTranslationHandler"
* },
* admin_permission = "administer blocks",
* base_table = "custom_block",
* revision_table = "custom_block_revision",
* base_table = "block_content",
* revision_table = "block_content_revision",
* links = {
* "canonical" = "custom_block.edit",
* "delete-form" = "custom_block.delete",
* "edit-form" = "custom_block.edit",
* "admin-form" = "custom_block.type_edit"
* "canonical" = "block_content.edit",
* "delete-form" = "block_content.delete",
* "edit-form" = "block_content.edit",
* "admin-form" = "block_content.type_edit"
* },
* fieldable = TRUE,
* translatable = TRUE,
@ -51,10 +51,10 @@ use Drupal\custom_block\CustomBlockInterface;
* "label" = "info",
* "uuid" = "uuid"
* },
* bundle_entity_type = "custom_block_type"
* bundle_entity_type = "block_content_type"
* )
*/
class CustomBlock extends ContentEntityBase implements CustomBlockInterface {
class BlockContent extends ContentEntityBase implements BlockContentInterface {
/**
* The theme the block is being created in.
@ -106,7 +106,7 @@ class CustomBlock extends ContentEntityBase implements CustomBlockInterface {
* {@inheritdoc}
*/
public function getInstances() {
return entity_load_multiple_by_properties('block', array('plugin' => 'custom_block:' . $this->uuid()));
return entity_load_multiple_by_properties('block', array('plugin' => 'block_content:' . $this->uuid()));
}
/**
@ -116,7 +116,7 @@ class CustomBlock extends ContentEntityBase implements CustomBlockInterface {
parent::preSaveRevision($storage, $record);
if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
// If we are updating an existing custom_block without adding a new
// 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->getRevisionLog();
@ -172,7 +172,7 @@ class CustomBlock extends ContentEntityBase implements CustomBlockInterface {
$fields['type'] = FieldDefinition::create('entity_reference')
->setLabel(t('Block type'))
->setDescription(t('The block type.'))
->setSetting('target_type', 'custom_block_type');
->setSetting('target_type', 'block_content_type');
$fields['revision_log'] = FieldDefinition::create('string_long')
->setLabel(t('Revision log message'))

View File

@ -0,0 +1,101 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Entity\BlockContentType.
*/
namespace Drupal\block_content\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\block_content\BlockContentTypeInterface;
/**
* Defines the custom block type entity.
*
* @ConfigEntityType(
* id = "block_content_type",
* label = @Translation("Custom block type"),
* controllers = {
* "form" = {
* "default" = "Drupal\block_content\BlockContentTypeForm",
* "add" = "Drupal\block_content\BlockContentTypeForm",
* "edit" = "Drupal\block_content\BlockContentTypeForm",
* "delete" = "Drupal\block_content\Form\BlockContentTypeDeleteForm"
* },
* "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" = "block_content.type_delete",
* "edit-form" = "block_content.type_edit"
* }
* )
*/
class BlockContentType extends ConfigEntityBundleBase implements BlockContentTypeInterface {
/**
* The custom block type ID.
*
* @var string
*/
public $id;
/**
* The custom block type label.
*
* @var string
*/
public $label;
/**
* The default revision setting for custom blocks of this type.
*
* @var bool
*/
public $revision;
/**
* The description of the block type.
*
* @var string
*/
public $description;
/**
* {@inheritdoc}
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
if (!$update && !$this->isSyncing()) {
entity_invoke_bundle_hook('create', 'block_content', $this->id());
if (!$this->isSyncing()) {
block_content_add_body_field($this->id);
}
}
elseif ($this->getOriginalId() != $this->id) {
entity_invoke_bundle_hook('rename', 'block_content', $this->getOriginalId(), $this->id);
}
}
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
foreach ($entities as $entity) {
entity_invoke_bundle_hook('delete', 'block_content', $entity->id());
}
}
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\block\Form\CustomBlockDeleteForm.
* Contains \Drupal\block\Form\BlockContentDeleteForm.
*/
namespace Drupal\custom_block\Form;
namespace Drupal\block_content\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Url;
@ -13,7 +13,7 @@ use Drupal\Core\Url;
/**
* Provides a confirmation form for deleting a custom block entity.
*/
class CustomBlockDeleteForm extends ContentEntityConfirmFormBase {
class BlockContentDeleteForm extends ContentEntityConfirmFormBase {
/**
* {@inheritdoc}
@ -56,8 +56,8 @@ class CustomBlockDeleteForm extends ContentEntityConfirmFormBase {
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('custom_block', 'Custom block %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route'] = new Url('custom_block.list');
watchdog('block_content', 'Custom block %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route'] = new Url('block_content.list');
}
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\Form\CustomBlockTypeDeleteForm.
* Contains \Drupal\block_content\Form\BlockContentTypeDeleteForm.
*/
namespace Drupal\custom_block\Form;
namespace Drupal\block_content\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\Query\QueryFactory;
@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a confirmation form for deleting a custom block type entity.
*/
class CustomBlockTypeDeleteForm extends EntityConfirmFormBase {
class BlockContentTypeDeleteForm extends EntityConfirmFormBase {
/**
* The query factory to create entity queries.
@ -54,7 +54,7 @@ class CustomBlockTypeDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getCancelRoute() {
return new Url('custom_block.type_list');
return new Url('block_content.type_list');
}
/**
@ -68,7 +68,7 @@ class CustomBlockTypeDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$blocks = $this->queryFactory->get('custom_block')->condition('type', $this->entity->id())->execute();
$blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute();
if (!empty($blocks)) {
$caption = '<p>' . format_plural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '</p>';
$form['description'] = array('#markup' => $caption);
@ -85,7 +85,7 @@ class CustomBlockTypeDeleteForm extends EntityConfirmFormBase {
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('custom_block', 'Custom block type %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
watchdog('block_content', 'Custom block type %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route'] = $this->getCancelRoute();
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\Plugin\Block\CustomBlockBlock.
* Contains \Drupal\block_content\Plugin\Block\BlockContentBlock.
*/
namespace Drupal\custom_block\Plugin\Block;
namespace Drupal\block_content\Plugin\Block;
use Drupal\block\BlockBase;
use Drupal\block\BlockManagerInterface;
@ -20,13 +20,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Defines a generic custom block type.
*
* @Block(
* id = "custom_block",
* id = "block_content",
* admin_label = @Translation("Custom block"),
* category = @Translation("Custom"),
* derivative = "Drupal\custom_block\Plugin\Derivative\CustomBlock"
* derivative = "Drupal\block_content\Plugin\Derivative\BlockContent"
* )
*/
class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterface {
class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The Plugin Block Manager.
@ -57,7 +57,7 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
protected $account;
/**
* Constructs a new CustomBlockBlock.
* Constructs a new BlockContentBlock.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
@ -121,9 +121,9 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
* Adds body and description fields to the block configuration form.
*/
public function blockForm($form, &$form_state) {
$form['custom_block']['view_mode'] = array(
$form['block_content']['view_mode'] = array(
'#type' => 'select',
'#options' => $this->entityManager->getViewModeOptions('custom_block'),
'#options' => $this->entityManager->getViewModeOptions('block_content'),
'#title' => t('View mode'),
'#description' => t('Output the block in this view mode.'),
'#default_value' => $this->configuration['view_mode']
@ -138,7 +138,7 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
public function blockSubmit($form, &$form_state) {
// Invalidate the block cache to update custom block-based derivatives.
if ($this->moduleHandler->moduleExists('block')) {
$this->configuration['view_mode'] = $form_state['values']['custom_block']['view_mode'];
$this->configuration['view_mode'] = $form_state['values']['block_content']['view_mode'];
$this->blockManager->clearCachedDefinitions();
}
}
@ -148,7 +148,7 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
*/
public function build() {
$uuid = $this->getDerivativeId();
if ($block = entity_load_by_uuid('custom_block', $uuid)) {
if ($block = entity_load_by_uuid('block_content', $uuid)) {
return entity_view($block, $this->configuration['view_mode']);
}
else {

View File

@ -0,0 +1,28 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Plugin\Derivative\BlockContent.
*/
namespace Drupal\block_content\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DerivativeBase;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
/**
* Retrieves block plugin definitions for all custom blocks.
*/
class BlockContent extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$block_contents = entity_load_multiple('block_content');
foreach ($block_contents as $block_content) {
$this->derivatives[$block_content->uuid()] = $base_plugin_definition;
$this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label();
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\Plugin\Menu\LocalAction\CustomBlockAddLocalAction.
* Contains \Drupal\block_content\Plugin\Menu\LocalAction\BlockContentAddLocalAction.
*/
namespace Drupal\custom_block\Plugin\Menu\LocalAction;
namespace Drupal\block_content\Plugin\Menu\LocalAction;
use Drupal\Core\Menu\LocalActionDefault;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
@ -14,7 +14,7 @@ use Symfony\Component\HttpFoundation\Request;
/**
* Modifies the 'Add custom block' local action.
*/
class CustomBlockAddLocalAction extends LocalActionDefault {
class BlockContentAddLocalAction extends LocalActionDefault {
/**
* {@inheritdoc}
@ -26,12 +26,12 @@ class CustomBlockAddLocalAction extends LocalActionDefault {
$options['query']['theme'] = $request->attributes->get('theme');
}
// Adds a destination on custom block listing.
if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'custom_block.list') {
$options['query']['destination'] = 'admin/structure/block/custom-blocks';
if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'block_content.list') {
$options['query']['destination'] = 'admin/structure/block/block-content';
}
// Adds a destination on custom block listing.
if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'custom_block.list') {
$options['query']['destination'] = 'admin/structure/block/custom-blocks';
if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'block_content.list') {
$options['query']['destination'] = 'admin/structure/block/block-content';
}
return $options;
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockCacheTagsTest.
* Contains \Drupal\block_content\Tests\BlockContentCacheTagsTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\Core\Entity\EntityInterface;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
@ -13,12 +13,12 @@ use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
/**
* Tests the Custom Block entity's cache tags.
*/
class CustomBlockCacheTagsTest extends EntityCacheTagsTestBase {
class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('custom_block');
public static $modules = array('block_content');
/**
* {@inheritdoc}
@ -32,7 +32,7 @@ class CustomBlockCacheTagsTest extends EntityCacheTagsTestBase {
*/
protected function createEntity() {
// Create a "Llama" custom block.
$custom_block = entity_create('custom_block', array(
$block_content = entity_create('block_content', array(
'info' => 'Llama',
'type' => 'basic',
'body' => array(
@ -40,9 +40,9 @@ class CustomBlockCacheTagsTest extends EntityCacheTagsTestBase {
'format' => 'plain_text',
),
));
$custom_block->save();
$block_content->save();
return $custom_block;
return $block_content;
}
/**

View File

@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockCreationTest.
* Contains \Drupal\block_content\Tests\BlockContentCreationTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\Core\Database\Database;
use Drupal\custom_block\Entity\CustomBlock;
use Drupal\block_content\Entity\BlockContent;
/**
* Tests creating and saving a block.
*/
class CustomBlockCreationTest extends CustomBlockTestBase {
class BlockContentCreationTest extends BlockContentTestBase {
/**
* Modules to enable.
@ -22,7 +22,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
*
* @var array
*/
public static $modules = array('custom_block_test', 'dblog');
public static $modules = array('block_content_test', 'dblog');
/**
* Declares test information.
@ -46,10 +46,10 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
/**
* Creates a "Basic page" block and verifies its consistency in the database.
*/
public function testCustomBlockCreation() {
public function testBlockContentCreation() {
// Add a new view mode and verify if it is selected as expected.
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
$this->drupalGet('admin/structure/display-modes/view/add/custom_block');
$this->drupalGet('admin/structure/display-modes/view/add/block_content');
$edit = array(
'id' => 'test_view_mode',
'label' => 'Test View Mode',
@ -72,18 +72,18 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
)), 'Basic block created.');
// Change the view mode.
$view_mode['settings[custom_block][view_mode]'] = 'test_view_mode';
$view_mode['settings[block_content][view_mode]'] = 'test_view_mode';
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
// Go to the configure page and verify that the new view mode is correct.
$this->drupalGet('admin/structure/block/manage/testblock');
$this->assertFieldByXPath('//select[@name="settings[custom_block][view_mode]"]/option[@selected="selected"]/@value', 'test_view_mode', 'View mode changed to Test View Mode');
$this->assertFieldByXPath('//select[@name="settings[block_content][view_mode]"]/option[@selected="selected"]/@value', 'test_view_mode', 'View mode changed to Test View Mode');
// Test the available view mode options.
$this->assertOption('edit-settings-custom-block-view-mode', 'default', 'The default view mode is available.');
$this->assertOption('edit-settings-block-content-view-mode', 'default', 'The default view mode is available.');
// Check that the block exists in the database.
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info[0][value]']));
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
$block = reset($blocks);
$this->assertTrue($block, 'Custom Block found in database.');
@ -104,7 +104,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
* Creates a custom block from defaults and ensures that the 'basic block'
* type is being used.
*/
public function testDefaultCustomBlockCreation() {
public function testDefaultBlockContentCreation() {
$edit = array();
$edit['info[0][value]'] = $this->randomName(8);
$edit['body[0][value]'] = $this->randomName(16);
@ -118,7 +118,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
)), 'Basic block created.');
// Check that the block exists in the database.
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info[0][value]']));
$blocks = entity_load_multiple_by_properties('block_content', array('info' => $edit['info[0][value]']));
$block = reset($blocks);
$this->assertTrue($block, 'Default Custom Block found in database.');
}
@ -129,7 +129,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
public function testFailedBlockCreation() {
// Create a block.
try {
$this->createCustomBlock('fail_creation');
$this->createBlockContent('fail_creation');
$this->fail('Expected exception has not been thrown.');
}
catch (\Exception $e) {
@ -138,7 +138,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
if (Database::getConnection()->supportsTransactions()) {
// Check that the block does not exist in the database.
$id = db_select('custom_block', 'b')
$id = db_select('block_content', 'b')
->fields('b', array('id'))
->condition('info', 'fail_creation')
->execute()
@ -147,7 +147,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
}
else {
// Check that the block exists in the database.
$id = db_select('custom_block', 'b')
$id = db_select('block_content', 'b')
->fields('b', array('id'))
->condition('info', 'fail_creation')
->execute()
@ -177,11 +177,11 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
'settings[label]' => $edit['info[0][value]'],
'region' => 'sidebar_first',
);
$block = entity_load('custom_block', 1);
$url = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
$block = entity_load('block_content', 1);
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
$this->drupalPostForm($url, $instance, t('Save block'));
$block = CustomBlock::load(1);
$block = BlockContent::load(1);
// Test getInstances method.
$this->assertEqual(1, count($block->getInstances()));

View File

@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockFieldTest.
* Contains \Drupal\block_content\Tests\BlockContentFieldTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
/**
* Tests the block edit functionality.
@ -13,14 +13,14 @@ namespace Drupal\custom_block\Tests;
* @todo Consider removing this test when https://drupal.org/node/1822000 is
* fixed.
*/
class CustomBlockFieldTest extends CustomBlockTestBase {
class BlockContentFieldTest extends BlockContentTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'custom_block', 'link');
public static $modules = array('block', 'block_content', 'link');
/**
* The created field.
@ -39,7 +39,7 @@ class CustomBlockFieldTest extends CustomBlockTestBase {
/**
* The block type.
*
* @var \Drupal\custom_block\Entity\CustomBlockType
* @var \Drupal\block_content\Entity\BlockContentType
*/
protected $blockType;
@ -61,12 +61,12 @@ class CustomBlockFieldTest extends CustomBlockTestBase {
public function testBlockFields() {
$this->drupalLogin($this->adminUser);
$this->blockType = $this->createCustomBlockType('link');
$this->blockType = $this->createBlockContentType('link');
// Create a field with settings to validate.
$this->field = entity_create('field_config', array(
'name' => drupal_strtolower($this->randomName()),
'entity_type' => 'custom_block',
'entity_type' => 'block_content',
'type' => 'link',
'cardinality' => 2,
));
@ -79,12 +79,12 @@ class CustomBlockFieldTest extends CustomBlockTestBase {
),
));
$this->instance->save();
entity_get_form_display('custom_block', 'link', 'default')
entity_get_form_display('block_content', 'link', 'default')
->setComponent($this->field->getName(), array(
'type' => 'link_default',
))
->save();
entity_get_display('custom_block', 'link', 'default')
entity_get_display('block_content', 'link', 'default')
->setComponent($this->field->getName(), array(
'type' => 'link',
'label' => 'hidden',
@ -99,8 +99,8 @@ class CustomBlockFieldTest extends CustomBlockTestBase {
$this->field->getName() . '[0][title]' => 'Example.com'
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$block = entity_load('custom_block', 1);
$url = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
$block = entity_load('block_content', 1);
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
// Place the block.
$instance = array(
'id' => drupal_strtolower($edit['info[0][value]']),

View File

@ -2,26 +2,26 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockListTest.
* Contains \Drupal\block_content\Tests\BlockContentListTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the listing of custom blocks.
*
* @see \Drupal\block\CustomBlockListBuilder
* @see \Drupal\block\BlockContentListBuilder
*/
class CustomBlockListTest extends WebTestBase {
class BlockContentListTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'custom_block', 'config_translation');
public static $modules = array('block', 'block_content', 'config_translation');
public static function getInfo() {
return array(
@ -36,7 +36,7 @@ class CustomBlockListTest extends WebTestBase {
*/
public function testListing() {
$this->drupalLogin($this->drupalCreateUser(array('administer blocks', 'translate configuration')));
$this->drupalGet('admin/structure/block/custom-blocks');
$this->drupalGet('admin/structure/block/block-content');
// Test for the page title.
$this->assertTitle(t('Custom block library') . ' | Drupal');
@ -82,7 +82,7 @@ class CustomBlockListTest extends WebTestBase {
// Edit the entity using the operations link.
$blocks = $this->container
->get('entity.manager')
->getStorage('custom_block')
->getStorage('block_content')
->loadByProperties(array('info' => $label));
$block = reset($blocks);
if (!empty($block)) {

View File

@ -2,22 +2,22 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockPageViewTest.
* Contains \Drupal\block_content\Tests\BlockContentPageViewTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
/**
* Tests the block edit functionality.
*/
class CustomBlockPageViewTest extends CustomBlockTestBase {
class BlockContentPageViewTest extends BlockContentTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'custom_block', 'custom_block_test');
public static $modules = array('block', 'block_content', 'block_content_test');
/**
* Declares test information.
@ -35,10 +35,10 @@ class CustomBlockPageViewTest extends CustomBlockTestBase {
*/
public function testPageEdit() {
$this->drupalLogin($this->adminUser);
$block = $this->createCustomBlock();
$block = $this->createBlockContent();
// Attempt to view the block.
$this->drupalGet('custom-block/' . $block->id());
$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');

View File

@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockRevisionsTest.
* Contains \Drupal\block_content\Tests\BlockContentRevisionsTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
/**
* Tests the block revision functionality.
*/
class CustomBlockRevisionsTest extends CustomBlockTestBase {
class BlockContentRevisionsTest extends BlockContentTestBase {
/**
* Stores blocks created during the test.
@ -42,7 +42,7 @@ class CustomBlockRevisionsTest extends CustomBlockTestBase {
parent::setUp();
// Create initial block.
$block = $this->createCustomBlock('initial');
$block = $this->createBlockContent('initial');
$blocks = array();
$logs = array();
@ -74,7 +74,7 @@ class CustomBlockRevisionsTest extends CustomBlockTestBase {
foreach ($blocks as $delta => $revision_id) {
// Confirm the correct revision text appears.
$loaded = entity_revision_load('custom_block', $revision_id);
$loaded = entity_revision_load('block_content', $revision_id);
// Verify revision log is the same.
$this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision !revision', array(
'!revision' => $loaded->getRevisionId(),
@ -97,7 +97,7 @@ class CustomBlockRevisionsTest extends CustomBlockTestBase {
// Verify that the non-default revision id is greater than the default
// revision id.
$default_revision = entity_load('custom_block', $loaded->id());
$default_revision = entity_load('block_content', $loaded->id());
$this->assertTrue($loaded->getRevisionId() > $default_revision->getRevisionId(), 'Revision id is greater than default revision id.');
}

View File

@ -2,25 +2,25 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockSaveTest.
* Contains \Drupal\block_content\Tests\BlockContentSaveTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\Core\Language\Language;
use Drupal\custom_block\Entity\CustomBlock;
use Drupal\block_content\Entity\BlockContent;
/**
* Tests block save related functionality.
*/
class CustomBlockSaveTest extends CustomBlockTestBase {
class BlockContentSaveTest extends BlockContentTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('custom_block_test');
public static $modules = array('block_content_test');
/**
* Declares test information.
@ -28,7 +28,7 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
public static function getInfo() {
return array(
'name' => 'Custom Block save',
'description' => 'Test $custom_block->save() for saving content.',
'description' => 'Test $block_content->save() for saving content.',
'group' => 'Custom Block',
);
}
@ -47,7 +47,7 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
*/
public function testImport() {
// Custom block ID must be a number that is not in the database.
$max_id = db_query('SELECT MAX(id) FROM {custom_block}')->fetchField();
$max_id = db_query('SELECT MAX(id) FROM {block_content}')->fetchField();
$test_id = $max_id + mt_rand(1000, 1000000);
$info = $this->randomName(8);
$block_array = array(
@ -56,7 +56,7 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
'type' => 'basic',
'id' => $test_id
);
$block = entity_create('custom_block', $block_array);
$block = entity_create('block_content', $block_array);
$block->enforceIsNew(TRUE);
$block->save();
@ -64,7 +64,7 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
$this->assertEqual($block->id(), $test_id, 'Block imported using provide id');
// Test the import saved.
$block_by_id = CustomBlock::load($test_id);
$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']);
}
@ -76,7 +76,7 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
*/
public function testDeterminingChanges() {
// Initial creation.
$block = $this->createCustomBlock('test_changes');
$block = $this->createBlockContent('test_changes');
$this->assertEqual($block->getChangedTime(), REQUEST_TIME, 'Creating a block sets default "changed" timestamp.');
// Update the block without applying changes.
@ -87,14 +87,14 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
$block->setInfo('updated');
$block->save();
// The hook implementations custom_block_test_custom_block_presave() and
// custom_block_test_custom_block_update() determine changes and change the
// 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 programatically 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 = CustomBlock::load($block->id());
$block = BlockContent::load($block->id());
$this->assertEqual($block->label(), 'updated_presave', 'Static cache has been cleared.');
}
@ -102,16 +102,16 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
* Tests saving a block on block insert.
*
* This test ensures that a block has been fully saved when
* hook_custom_block_insert() is invoked, so that the block can be saved again
* 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 testCustomBlockSaveOnInsert() {
// custom_block_test_custom_block_insert() triggers a save on insert if the
public function testBlockContentSaveOnInsert() {
// block_content_test_block_content_insert() triggers a save on insert if the
// title equals 'new'.
$block = $this->createCustomBlock('new');
$this->assertEqual($block->label(), 'CustomBlock ' . $block->id(), 'Custom block saved on block insert.');
$block = $this->createBlockContent('new');
$this->assertEqual($block->label(), 'BlockContent ' . $block->id(), 'Custom block saved on block insert.');
}
}

View File

@ -2,17 +2,17 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockTestBase.
* Contains \Drupal\block_content\Tests\BlockContentTestBase.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Sets up page and article content types.
*/
abstract class CustomBlockTestBase extends WebTestBase {
abstract class BlockContentTestBase extends WebTestBase {
/**
* Profile to use.
@ -40,7 +40,7 @@ abstract class CustomBlockTestBase extends WebTestBase {
*
* @var array
*/
public static $modules = array('block', 'custom_block');
public static $modules = array('block', 'block_content');
/**
* Sets the test up.
@ -59,19 +59,19 @@ abstract class CustomBlockTestBase extends WebTestBase {
* @param string $bundle
* (optional) Bundle name. Defaults to 'basic'.
*
* @return \Drupal\custom_block\Entity\CustomBlock
* @return \Drupal\block_content\Entity\BlockContent
* Created custom block.
*/
protected function createCustomBlock($title = FALSE, $bundle = 'basic') {
protected function createBlockContent($title = FALSE, $bundle = 'basic') {
$title = ($title ? : $this->randomName());
if ($custom_block = entity_create('custom_block', array(
if ($block_content = entity_create('block_content', array(
'info' => $title,
'type' => $bundle,
'langcode' => 'en'
))) {
$custom_block->save();
$block_content->save();
}
return $custom_block;
return $block_content;
}
/**
@ -80,11 +80,11 @@ abstract class CustomBlockTestBase extends WebTestBase {
* @param string $label
* The block type label.
*
* @return \Drupal\custom_block\Entity\CustomBlockType
* @return \Drupal\block_content\Entity\BlockContentType
* Created custom block type.
*/
protected function createCustomBlockType($label) {
$bundle = entity_create('custom_block_type', array(
protected function createBlockContentType($label) {
$bundle = entity_create('block_content_type', array(
'id' => $label,
'label' => $label,
'revision' => FALSE

View File

@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockTranslationUITest.
* Contains \Drupal\block_content\Tests\BlockContentTranslationUITest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\content_translation\Tests\ContentTranslationUITest;
use Drupal\custom_block\Entity\CustomBlock;
use Drupal\block_content\Entity\BlockContent;
/**
* Tests the Custom Block Translation UI.
*/
class CustomBlockTranslationUITest extends ContentTranslationUITest {
class BlockContentTranslationUITest extends ContentTranslationUITest {
/**
* The name of the test block.
@ -30,7 +30,7 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
'content_translation',
'block',
'field_ui',
'custom_block'
'block_content'
);
/**
@ -48,7 +48,7 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
* Overrides \Drupal\simpletest\WebTestBase::setUp().
*/
public function setUp() {
$this->entityTypeId = 'custom_block';
$this->entityTypeId = 'block_content';
$this->bundle = 'basic';
$this->name = drupal_strtolower($this->randomName());
$this->testLanguageSelector = FALSE;
@ -63,7 +63,7 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
'translate any entity',
'access administration pages',
'administer blocks',
'administer custom_block fields'
'administer block_content fields'
));
}
@ -77,19 +77,19 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
* (optional) Bundle name. When no value is given, defaults to
* $this->bundle. Defaults to FALSE.
*
* @return \Drupal\custom_block\Entity\CustomBlock
* @return \Drupal\block_content\Entity\BlockContent
* Created custom block.
*/
protected function createCustomBlock($title = FALSE, $bundle = FALSE) {
protected function createBlockContent($title = FALSE, $bundle = FALSE) {
$title = ($title ? : $this->randomName());
$bundle = ($bundle ? : $this->bundle);
$custom_block = entity_create('custom_block', array(
$block_content = entity_create('block_content', array(
'info' => $title,
'type' => $bundle,
'langcode' => 'en'
));
$custom_block->save();
return $custom_block;
$block_content->save();
return $block_content;
}
/**
@ -119,7 +119,7 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
public function testDisabledBundle() {
// Create a bundle that does not have translation enabled.
$disabled_bundle = $this->randomName();
$bundle = entity_create('custom_block_type', array(
$bundle = entity_create('block_content_type', array(
'id' => $disabled_bundle,
'label' => $disabled_bundle,
'revision' => FALSE
@ -127,14 +127,14 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
$bundle->save();
// Create a node for each bundle.
$enabled_custom_block = $this->createCustomBlock();
$disabled_custom_block = $this->createCustomBlock(FALSE, $bundle->id());
$enabled_block_content = $this->createBlockContent();
$disabled_block_content = $this->createBlockContent(FALSE, $bundle->id());
// Make sure that only a single row was inserted into the
// {content_translation} table.
$rows = db_query('SELECT * FROM {content_translation}')->fetchAll();
$this->assertEqual(1, count($rows));
$this->assertEqual($enabled_custom_block->id(), reset($rows)->entity_id);
$this->assertEqual($enabled_block_content->id(), reset($rows)->entity_id);
}
}

View File

@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\CustomBlockTypeTest.
* Contains \Drupal\block_content\Tests\BlockContentTypeTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
/**
* Tests related to custom block types.
*/
class CustomBlockTypeTest extends CustomBlockTestBase {
class BlockContentTypeTest extends BlockContentTestBase {
/**
* Modules to enable.
@ -26,7 +26,7 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
*/
protected $permissions = array(
'administer blocks',
'administer custom_block fields'
'administer block_content fields'
);
/**
@ -34,7 +34,7 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
*/
public static function getInfo() {
return array(
'name' => 'CustomBlock types',
'name' => 'Custom Block types',
'description' => 'Ensures that custom block type functions work correctly.',
'group' => 'Custom Block',
);
@ -43,11 +43,11 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
/**
* Tests creating a block type programmatically and via a form.
*/
public function testCustomBlockTypeCreation() {
public function testBlockContentTypeCreation() {
// Create a block type programmaticaly.
$type = $this->createCustomBlockType('other');
$type = $this->createBlockContentType('other');
$block_type = entity_load('custom_block_type', 'other');
$block_type = entity_load('block_content_type', 'other');
$this->assertTrue($block_type, 'The new block type has been created.');
// Login a test user.
@ -61,8 +61,8 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
'id' => 'foo',
'label' => 'title for foo',
);
$this->drupalPostForm('admin/structure/block/custom-blocks/types/add', $edit, t('Save'));
$block_type = entity_load('custom_block_type', 'foo');
$this->drupalPostForm('admin/structure/block/block-content/types/add', $edit, t('Save'));
$block_type = entity_load('block_content_type', 'foo');
$this->assertTrue($block_type, 'The new block type has been created.');
// Check that the block type was created in site default language.
@ -73,12 +73,12 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
/**
* Tests editing a block type using the UI.
*/
public function testCustomBlockTypeEditing() {
public function testBlockContentTypeEditing() {
$this->drupalLogin($this->adminUser);
// We need two block types to prevent /block/add redirecting.
$this->createCustomBlockType('other');
$this->createBlockContentType('other');
$field_definition = \Drupal::entityManager()->getFieldDefinitions('custom_block', 'other')['body'];
$field_definition = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other')['body'];
$this->assertEqual($field_definition->getLabel(), 'Body', 'Body field was found.');
// Verify that title and body fields are displayed.
@ -90,7 +90,8 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
$edit = array(
'label' => 'Bar',
);
$this->drupalPostForm('admin/structure/block/custom-blocks/manage/basic', $edit, t('Save'));
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', $edit, t('Save'));
\Drupal::entityManager()->clearCachedFieldDefinitions();
$this->drupalGet('block/add');
$this->assertRaw('Bar', 'New name was displayed.');
@ -98,9 +99,9 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
$this->assertEqual(url('block/add/basic', array('absolute' => TRUE)), $this->getUrl(), 'Original machine name was used in URL.');
// Remove the body field.
$this->drupalPostForm('admin/structure/block/custom-blocks/manage/basic/fields/custom_block.basic.body/delete', array(), t('Delete'));
$this->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', array(), t('Delete'));
// Resave the settings for this type.
$this->drupalPostForm('admin/structure/block/custom-blocks/manage/basic', array(), t('Save'));
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', array(), t('Save'));
// Check that the body field doesn't exist.
$this->drupalGet('block/add/basic');
$this->assertNoRaw('Body', 'Body field was not found.');
@ -109,16 +110,16 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
/**
* Tests deleting a block type that still has content.
*/
public function testCustomBlockTypeDeletion() {
public function testBlockContentTypeDeletion() {
// Create a block type programmatically.
$type = $this->createCustomBlockType('foo');
$type = $this->createBlockContentType('foo');
$this->drupalLogin($this->adminUser);
// Add a new block of this type.
$block = $this->createCustomBlock(FALSE, 'foo');
$block = $this->createBlockContent(FALSE, 'foo');
// Attempt to delete the block type, which should not be allowed.
$this->drupalGet('admin/structure/block/custom-blocks/manage/' . $type->id() . '/delete');
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
$this->assertRaw(
t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', array('%label' => $type->label())),
'The block type will not be deleted until all blocks of that type are removed.'
@ -128,7 +129,7 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
// Delete the block.
$block->delete();
// Attempt to delete the block type, which should now be allowed.
$this->drupalGet('admin/structure/block/custom-blocks/manage/' . $type->id() . '/delete');
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
$this->assertRaw(
t('Are you sure you want to delete %type?', array('%type' => $type->id())),
'The block type is available for deletion.'
@ -139,16 +140,16 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
/**
* Tests that redirects work as expected when multiple block types exist.
*/
public function testsCustomBlockAddTypes() {
public function testsBlockContentAddTypes() {
$this->drupalLogin($this->adminUser);
// Create two block types programmatically.
$type = $this->createCustomBlockType('foo');
$type = $this->createCustomBlockType('bar');
$type = $this->createBlockContentType('foo');
$type = $this->createBlockContentType('bar');
// Get the custom block storage.
$storage = $this->container
->get('entity.manager')
->getStorage('custom_block');
->getStorage('block_content');
// Enable all themes.
theme_enable(array('bartik', 'seven'));
@ -182,7 +183,7 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
$blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]']));
if (!empty($blocks)) {
$block = reset($blocks);
$destination = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . $theme;
$destination = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $theme;
$this->assertUrl(url($destination, array('absolute' => TRUE)));
$this->drupalPostForm(NULL, array(), t('Save block'));
$this->assertUrl(url("admin/structure/block/list/$theme", array('absolute' => TRUE, 'query' => array('block-placement' => drupal_html_class($edit['info[0][value]'])))));
@ -195,14 +196,14 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
// Test that adding a block from the 'custom blocks list' doesn't send you
// to the block configure form.
$this->drupalGet('admin/structure/block/custom-blocks');
$this->drupalGet('admin/structure/block/block-content');
$this->clickLink(t('Add custom block'));
$this->clickLink('foo');
$edit = array('info[0][value]' => $this->randomName(8));
$this->drupalPostForm(NULL, $edit, t('Save'));
$blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]']));
if (!empty($blocks)) {
$destination = 'admin/structure/block/custom-blocks';
$destination = 'admin/structure/block/block-content';
$this->assertUrl(url($destination, array('absolute' => TRUE)));
}
else {

View File

@ -2,17 +2,17 @@
/**
* @file
* Contains \Drupal\custom_block\Tests\PageEditTest.
* Contains \Drupal\block_content\Tests\PageEditTest.
*/
namespace Drupal\custom_block\Tests;
namespace Drupal\block_content\Tests;
use Drupal\Core\Language\Language;
/**
* Tests the block edit functionality.
*/
class PageEditTest extends CustomBlockTestBase {
class PageEditTest extends BlockContentTestBase {
/**
* Declares test information.
@ -40,8 +40,8 @@ class PageEditTest extends CustomBlockTestBase {
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the block exists in the database.
$blocks = \Drupal::entityQuery('custom_block')->condition('info', $edit['info[0][value]'])->execute();
$block = entity_load('custom_block', reset($blocks));
$blocks = \Drupal::entityQuery('block_content')->condition('info', $edit['info[0][value]'])->execute();
$block = entity_load('block_content', reset($blocks));
$this->assertTrue($block, 'Custom block found in database.');
// Load the edit page.
@ -65,7 +65,7 @@ class PageEditTest extends CustomBlockTestBase {
$this->drupalPostForm(NULL, $edit, t('Save'));
// Ensure that the block revision has been created.
$revised_block = entity_load('custom_block', $block->id(), TRUE);
$revised_block = entity_load('block_content', $block->id(), TRUE);
$this->assertNotIdentical($block->getRevisionId(), $revised_block->getRevisionId(), 'A new revision has been created.');
// Test deleting the block.

View File

@ -9,7 +9,7 @@
* - link: A link to add a block of this type.
* - description: A description of this custom block type.
*
* @see template_preprocess_custom_block_add_list()
* @see template_preprocess_block_content_add_list()
*
* @ingroup themeable
*/

View File

@ -0,0 +1,68 @@
<?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'] = array(
'#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->save();
}
if ($block_content->label() == 'fail_creation') {
throw new Exception('Test exception for rollback.');
}
}

View File

@ -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'

View File

@ -0,0 +1,94 @@
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Menu\BlockContentLocalTasksTest.
*/
namespace Drupal\block_content\Tests\Menu;
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTest;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Tests existence of block_content local tasks.
*
* @group Drupal
* @group Block
*/
class BlockContentLocalTasksTest extends LocalTaskIntegrationTest {
public static function getInfo() {
return array(
'name' => 'Custom Block local tasks test',
'description' => 'Test block_content local tasks.',
'group' => 'Block',
);
}
public function setUp() {
$this->directoryList = array(
'block' => 'core/modules/block',
'block_content' => 'core/modules/block_content',
);
parent::setUp();
$config_factory = $this->getConfigFactoryStub(array('system.theme' => array(
'default' => 'test_c',
)));
$themes = array();
$themes['test_a'] = (object) array(
'status' => 0,
);
$themes['test_b'] = (object) array(
'status' => 1,
'info' => array(
'name' => 'test_b',
),
);
$themes['test_c'] = (object) array(
'status' => 1,
'info' => array(
'name' => 'test_c',
),
);
$theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
$theme_handler->expects($this->any())
->method('listInfo')
->will($this->returnValue($themes));
$container = new ContainerBuilder();
$container->set('config.factory', $config_factory);
$container->set('theme_handler', $theme_handler);
\Drupal::setContainer($container);
}
/**
* Checks block_content listing local tasks.
*
* @dataProvider getBlockContentListingRoutes
*/
public function testBlockContentListLocalTasks($route) {
$this->assertLocalTasks($route, array(
0 => array(
'block.admin_display',
'block_content.list',
),
1 => array(
'block_content.list_sub',
'block_content.type_list',
),
));
}
/**
* Provides a list of routes to test.
*/
public function getBlockContentListingRoutes() {
return array(
array('block_content.list', 'block_content.type_list'),
);
}
}

View File

@ -27,7 +27,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
'block',
'config_translation',
'contact',
'custom_block',
'block_content',
'field',
'field_ui',
'menu_ui',
@ -62,7 +62,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
'administer blocks',
'administer contact forms',
'administer content types',
'administer custom_block fields',
'administer block_content fields',
'administer filters',
'administer menu',
'administer node fields',
@ -187,20 +187,20 @@ class ConfigTranslationListUiTest extends WebTestBase {
/**
* Tests the custom block listing for the translate operation.
*/
public function doCustomBlockTypeListTest() {
public function doCustomContentTypeListTest() {
// Create a test custom block type to decouple looking for translate
// operations link so this does not test more than necessary.
$custom_block_type = entity_create('custom_block_type', array(
$block_content_type = entity_create('block_content_type', array(
'id' => Unicode::strtolower($this->randomName(16)),
'label' => $this->randomName(),
'revision' => FALSE
));
$custom_block_type->save();
$block_content_type->save();
// Get the custom block type listing.
$this->drupalGet('admin/structure/block/custom-blocks/types');
$this->drupalGet('admin/structure/block/block-content/types');
$translate_link = 'admin/structure/block/custom-blocks/manage/' . $custom_block_type->id() . '/translate';
$translate_link = 'admin/structure/block/block-content/manage/' . $block_content_type->id() . '/translate';
// Test if the link to translate the custom block type is on the page.
$this->assertLinkByHref($translate_link);
@ -404,8 +404,8 @@ class ConfigTranslationListUiTest extends WebTestBase {
'field' => 'node.' . $content_type->id() . '.body',
),
array(
'list' => 'admin/structure/block/custom-blocks/manage/basic/fields',
'field' => 'custom_block.basic.body',
'list' => 'admin/structure/block/block-content/manage/basic/fields',
'field' => 'block_content.basic.body',
),
);
@ -466,7 +466,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
$this->doBlockListTest();
$this->doMenuListTest();
$this->doVocabularyListTest();
$this->doCustomBlockTypeListTest();
$this->doCustomContentTypeListTest();
$this->doContactFormsListTest();
$this->doContentTypeListTest();
$this->doFormatsListTest();

View File

@ -14,7 +14,7 @@ process:
source: format
'body.value': body
destination:
plugin: entity:custom_block
plugin: entity:block_content
migration_dependencies:
required:
- d6_filter_format

View File

@ -32,14 +32,14 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
/**
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $customBlockStorage;
protected $blockContentStorage;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, MigratePluginManager $process_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->customBlockStorage = $storage;
$this->blockContentStorage = $storage;
$this->migration = $migration;
$this->processPluginManager = $process_plugin_manager;
}
@ -54,7 +54,7 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
$plugin_id,
$plugin_definition,
$migration,
$entity_manager->getDefinition('custom_block') ? $entity_manager->getStorage('custom_block') : NULL,
$entity_manager->getDefinition('block_content') ? $entity_manager->getStorage('block_content') : NULL,
$container->get('plugin.manager.migrate.process')
);
}
@ -80,11 +80,11 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
$value = "system_menu_block:$delta";
break;
case 'block':
if ($this->customBlockStorage) {
if ($this->blockContentStorage) {
$block_ids = $this->processPluginManager
->createInstance('migration', array('migration' => 'd6_custom_block'), $this->migration)
->transform($delta, $migrate_executable, $row, $destination_property);
$value = 'custom_block:' . $this->customBlockStorage->load($block_ids[0])->uuid();
$value = 'block_content:' . $this->blockContentStorage->load($block_ids[0])->uuid();
}
else {
throw new MigrateSkipRowException();

View File

@ -2,22 +2,22 @@
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCustomBlockTest.
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateBlockContentTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Language\Language;
use Drupal\custom_block\Entity\CustomBlock;
use Drupal\block_content\Entity\BlockContent;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
/**
* Tests the Drupal 6 custom block to Drupal 8 migration.
*/
class MigrateCustomBlockTest extends MigrateDrupalTestBase {
class MigrateBlockContentTest extends MigrateDrupalTestBase {
static $modules = array('block', 'custom_block');
static $modules = array('block', 'block_content');
/**
* {@inheritdoc}
@ -54,8 +54,8 @@ class MigrateCustomBlockTest extends MigrateDrupalTestBase {
* Tests the Drupal 6 custom block to Drupal 8 migration.
*/
public function testBlockMigration() {
/** @var CustomBlock $block */
$block = entity_load('custom_block', 1);
/** @var BlockContent $block */
$block = entity_load('block_content', 1);
$this->assertEqual('My block 1', $block->label());
$this->assertEqual(1, $block->getRevisionId());
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
@ -63,7 +63,7 @@ class MigrateCustomBlockTest extends MigrateDrupalTestBase {
$this->assertEqual('<h3>My first custom block body</h3>', $block->body->value);
$this->assertEqual('full_html', $block->body->format);
$block = entity_load('custom_block', 2);
$block = entity_load('block_content', 2);
$this->assertEqual('My block 2', $block->label());
$this->assertEqual(2, $block->getRevisionId());
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());

View File

@ -25,7 +25,7 @@ class MigrateBlockTest extends MigrateDrupalTestBase {
'views',
'comment',
'menu_ui',
'custom_block',
'block_content',
'node',
);
@ -48,8 +48,8 @@ class MigrateBlockTest extends MigrateDrupalTestBase {
$entities = array(
entity_create('menu', array('id' => 'primary-links')),
entity_create('menu', array('id' => 'secondary-links')),
entity_create('custom_block', array('id' => 1, 'type' => 'basic', 'info' => $this->randomName(8))),
entity_create('custom_block', array('id' => 2, 'type' => 'basic', 'info' => $this->randomName(8))),
entity_create('block_content', array('id' => 1, 'type' => 'basic', 'info' => $this->randomName(8))),
entity_create('block_content', array('id' => 2, 'type' => 'basic', 'info' => $this->randomName(8))),
);
foreach ($entities as $entity) {
$entity->enforceIsNew(TRUE);

View File

@ -26,7 +26,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
'book',
'comment',
'contact',
'custom_block',
'block_content',
'datetime',
'dblog',
'file',
@ -235,7 +235,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
__NAMESPACE__ . '\MigrateCommentVariableInstance',
__NAMESPACE__ . '\MigrateContactCategoryTest',
__NAMESPACE__ . '\MigrateContactConfigsTest',
__NAMESPACE__ . '\MigrateCustomBlockTest',
__NAMESPACE__ . '\MigrateBlockContentTest',
__NAMESPACE__ . '\MigrateDateFormatTest',
__NAMESPACE__ . '\MigrateDblogConfigsTest',
__NAMESPACE__ . '\MigrateFieldConfigsTest',

View File

@ -434,7 +434,7 @@
* @param Object contextualLink
* An object with the following properties:
* - String entityID: a Quick Edit entity identifier, e.g. "node/1" or
* "custom_block/5".
* "block_content/5".
* - String entityInstanceID: a Quick Edit entity instance identifier,
* e.g. 0, 1 or n (depending on whether it's the first, second, or n+1st
* instance of this entity).

View File

@ -15,7 +15,7 @@ dependencies:
- contextual
- contact
- datetime
- custom_block
- block_content
- quickedit
- editor
- entity_reference

View File

@ -136,11 +136,11 @@ function seven_node_add_list($variables) {
}
/**
* Overrides theme_custom_block_add_list().
* Overrides theme_block_content_add_list().
*
* Displays the list of available custom block types for creation.
*/
function seven_custom_block_add_list($variables) {
function seven_block_content_add_list($variables) {
$output = '';
if (!empty($variables['types'])) {
$output = '<ul class="admin-list">';
@ -150,7 +150,7 @@ function seven_custom_block_add_list($variables) {
$content .= '<div class="description">' . Xss::filterAdmin($type['description']) . '</div>';
$options = $type['localized_options'];
$options['html'] = TRUE;
$output .= \Drupal::l($content, 'custom_block.add_form', array('custom_block_type' => $id), $options);
$output .= \Drupal::l($content, 'block_content.add_form', array('block_content_type' => $id), $options);
$output .= '</li>';
}
$output .= '</ul>';