Commit a549c01b authored by alexpott's avatar alexpott

Issue #2030597 by adci_contributor, larowlan, daffie, Thomas Brekelmans,...

Issue #2030597 by adci_contributor, larowlan, daffie, Thomas Brekelmans, boztek, chakrapani, InternetDevels, robbertnl, basvanderheijden: Expand BlockContent and BlockContentType with methods
parent 87be19c9
......@@ -28,7 +28,7 @@ function template_preprocess_block_content_add_list(&$variables) {
foreach ($variables['content'] as $type) {
$variables['types'][$type->id()] = array(
'link' => \Drupal::l($type->label(), new Url('block_content.add_form', array('block_content_type' => $type->id()), array('query' => $query))),
'description' => Xss::filterAdmin($type->description),
'description' => Xss::filterAdmin($type->getDescription()),
'title' => $type->label(),
'localized_options' => array(
'query' => $query,
......
......@@ -74,8 +74,8 @@ public static function create(ContainerInterface $container) {
*
* Prepares the custom block object.
*
* Fills in a few default values, and then invokes hook_block_content_prepare()
* on all modules.
* Fills in a few default values, and then invokes
* hook_block_content_prepare() on all modules.
*/
protected function prepareEntity() {
$block = $this->entity;
......@@ -85,7 +85,7 @@ protected function prepareEntity() {
$block->setRevisionLog(NULL);
}
// Always use the default revision setting.
$block->setNewRevision($block_type->revision);
$block->setNewRevision($block_type->shouldCreateNewRevision());
}
/**
......
......@@ -48,9 +48,9 @@ public function setRevisionLog($revision_log);
/**
* Sets the theme value.
*
* When creating a new custom block from the block library, the user is
* When creating a new block content block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the custom block add form is shown.
* theme is stored against the block when the block content add form is shown.
*
* @param string $theme
* The theme name.
......@@ -63,9 +63,9 @@ public function setTheme($theme);
/**
* Gets the theme value.
*
* When creating a new custom block from the block library, the user is
* When creating a new block content block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the custom block add form is shown.
* theme is stored against the block when the block content add form is shown.
*
* @return string
* The theme name.
......
......@@ -25,6 +25,7 @@ class BlockContentTypeForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
$block_type = $this->entity;
$form['label'] = array(
......@@ -47,7 +48,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['description'] = array(
'#type' => 'textarea',
'#default_value' => $block_type->description,
'#default_value' => $block_type->getDescription(),
'#description' => t('Enter a description for this block type.'),
'#title' => t('Description'),
);
......@@ -55,7 +56,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $block_type->revision,
'#default_value' => $block_type->shouldCreateNewRevision(),
'#description' => t('Create a new revision by default for this block type.')
);
......
......@@ -14,4 +14,20 @@
*/
interface BlockContentTypeInterface extends ConfigEntityInterface {
/**
* Returns the description of the block type.
*
* @return string
* The description of the type of this block.
*/
public function getDescription();
/**
* Returns whether a new revision should be created by default.
*
* @return bool
* TRUE if a new revision should be created by default.
*/
public function shouldCreateNewRevision();
}
......@@ -45,7 +45,7 @@ public function buildHeader() {
*/
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity->link();
$row['description'] = Xss::filterAdmin($entity->description);
$row['description'] = Xss::filterAdmin($entity->getDescription());
return $row + parent::buildRow($entity);
}
......
......@@ -47,27 +47,41 @@ class BlockContentType extends ConfigEntityBundleBase implements BlockContentTyp
*
* @var string
*/
public $id;
protected $id;
/**
* The custom block type label.
*
* @var string
*/
public $label;
protected $label;
/**
* The default revision setting for custom blocks of this type.
*
* @var bool
*/
public $revision;
protected $revision;
/**
* The description of the block type.
*
* @var string
*/
public $description;
protected $description;
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->description;
}
/**
* {@inheritdoc}
*/
public function shouldCreateNewRevision() {
return $this->revision;
}
}
......@@ -90,7 +90,7 @@ function seven_preprocess_block_content_add_list(&$variables) {
if (!empty($variables['content'])) {
foreach ($variables['content'] as $type) {
$variables['types'][$type->id()]['label'] = String::checkPlain($type->label());
$variables['types'][$type->id()]['description'] = Xss::filterAdmin($type->description);
$variables['types'][$type->id()]['description'] = Xss::filterAdmin($type->getDescription());
$options = array('query' => \Drupal::request()->query->all());
$variables['types'][$type->id()]['url'] = \Drupal::url('block_content.add_form', array('block_content_type' => $type->id()), $options);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment