' . t('About') . ''; $output .= '
' . 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 Field module help for more information. Once created, custom blocks can be placed like blocks provided by other modules; see the Block module help page for details. For more information, see the online documentation for the Custom Block module.', 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')) . '
'; $output .= '' . 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.') . '
'; return $output; case 'admin/structure/block/custom-blocks/types': $output = '' . 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.') . '
'; return $output; } } /** * Implements hook_menu_link_defaults(). */ function custom_block_menu_link_defaults() { $links['custom_block.add_page'] = array( 'link_title' => 'Add custom block', 'description' => 'Add custom block', 'route_name' => 'custom_block.add_page', ); $items['custom_block.list'] = array( 'link_title' => 'Custom block library', 'parent' => 'block.admin.structure', 'description' => 'Manage custom blocks.', ); return $links; } /** * Implements hook_theme(). */ function custom_block_theme($existing, $type, $theme, $path) { return array( 'custom_block_add_list' => array( 'variables' => array('content' => NULL), 'file' => 'custom_block.pages.inc', 'template' => 'custom-block-add-list', ), ); } /** * Loads a custom block type. * * @param int $id * The ID of the custom block type to load. * * @return \Drupal\custom_block\Entity\CustomBlockType|null * A CustomBlockType object or NULL if the requested $id does not exist. */ function custom_block_type_load($id) { return entity_load('custom_block_type', $id); } /** * Loads a custom block. * * @param int $id * The id of the custom block. * * @return \Drupal\custom_block\Entity\CustomBlock|null * A CustomBlock object or NULL if the requested $id does not exist. */ function custom_block_load($id) { return entity_load('custom_block', $id); } /** * Implements hook_entity_type_alter(). */ function custom_block_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); } } /** * Implements hook_entity_bundle_info(). */ function custom_block_entity_bundle_info() { $bundles = array(); foreach (\Drupal::configFactory()->listAll('custom_block.type.') as $config_name) { $config = \Drupal::config($config_name); $bundles['custom_block'][$config->get('id')]['label'] = $config->get('label'); } return $bundles; } /** * Adds the default body field to a custom block type. * * @param string $block_type_id * Id of the block type. * @param string $label * (optional) The label for the body instance. Defaults to 'Block body' * * @return array() * Body field instance. */ function custom_block_add_body_field($block_type_id, $label = 'Block body') { // Add or remove the body field, as needed. $field = field_info_field('custom_block', 'body'); $instance = field_info_instance('custom_block', 'body', $block_type_id); if (empty($field)) { $field = entity_create('field_config', array( 'name' => 'body', 'entity_type' => 'custom_block', 'type' => 'text_with_summary', )); $field->save(); } if (empty($instance)) { $instance = entity_create('field_instance_config', array( 'field_name' => 'body', 'entity_type' => 'custom_block', 'bundle' => $block_type_id, 'label' => $label, 'settings' => array('display_summary' => FALSE), )); $instance->save(); // Assign widget settings for the 'default' form mode. entity_get_form_display('custom_block', $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') ->setComponent('body', array( 'label' => 'hidden', 'type' => 'text_default', )) ->save(); } return $instance; } /** * Implements hook_admin_paths(). */ function custom_block_admin_paths() { $paths = array( 'block/add' => TRUE, 'block/add/*' => TRUE, 'block/*' => TRUE, 'block/*/delete' => TRUE, 'admin/structure/block/custom-blocks/*' => TRUE, ); return $paths; }