diff --git a/core/modules/block/custom_block/custom_block.info b/core/modules/block/custom_block/custom_block.info new file mode 100644 index 0000000..f9e8f05 --- /dev/null +++ b/core/modules/block/custom_block/custom_block.info @@ -0,0 +1,6 @@ +name = Custom Block +description = Allows the ability to create custom blocks through the block interface. +package = Core +version = VERSION +core = 8.x +dependencies[] = block diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module new file mode 100644 index 0000000..8db2989 --- /dev/null +++ b/core/modules/block/custom_block/custom_block.module @@ -0,0 +1,24 @@ + array( + 'variables' => array('body' => NULL, 'format' => NULL), + ), + ); +} + +/** + * Returns HTML for a custom block. + * + * @ingroup themeable + */ +function theme_custom_block_block($variables) { + $body = $variables['body']; + $format = $variables['format']; + + return check_markup($body, $format); +} diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php new file mode 100644 index 0000000..a69817b --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php @@ -0,0 +1,104 @@ +configuration['info']; + return $definition; + } + + /** + * Implements BlockInterface::getConfig(). + */ + public function getConfig() { + $this->configuration = parent::getConfig(); + $block = db_select('block_custom', 'b') + ->fields('b') + ->condition('bid', $this->configuration['bid']) + ->execute() + ->fetchAssoc(); + $this->configuration['info'] = $block['info']; + $this->configuration['body'] = $block['body']; + $this->configuration['format'] = $block['format']; + return $this->configuration; + } + + /** + * Implements BlockInterface::configure(). + */ + public function configure($form, &$form_state) { + $form = parent::configure($form, $form_state); + $form['settings']['info'] = array( + '#type' => 'textfield', + '#title' => t('Block description'), + '#required' => TRUE, + '#default_value' => $this->configuration['info'], + '#description' => t('A brief description of your block. Used on the Blocks administration page.', array('@overview' => url('admin/structure/block'))), + ); + $form['settings']['body'] = array( + '#type' => 'text_format', + '#title' => t('Block body'), + '#default_value' => $this->configuration['body'], + '#format' => isset($this->configuration['format']) ? $this->configuration['format'] : filter_default_format(), + '#description' => t('The content of the block as shown to the user.'), + '#rows' => 15, + '#required' => TRUE, + ); + $form['settings']['title']['#description'] = t('The title of the block as shown to the user.'); + return $form; + } + + /** + * Implements BlockInterface::configureSubmit(). + */ + public function configureSubmit($form, &$form_state) { + parent::configureSubmit($form, $form_state); + $block = array( + 'info' => $form_state['values']['info'], + 'body' => $form_state['values']['body']['value'], + 'format' => $form_state['values']['body']['format'], + ); + if (isset($this->configuration['bid'])) { + $block['bid'] = $this->configuration['bid']; + drupal_write_record('block_custom', $block, array('bid')); + } + else { + drupal_write_record('block_custom', $block); + $this->configuration['bid'] = $block['bid']; + } + } + + /** + * Implements BlockInterface::build(); + */ + public function build() { + return array( + '#theme' => 'custom_block_block', + '#body' => $this->configuration['body'], + '#format' => $this->configuration['format'], + ); + } +}