' . 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('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating and managing custom block types') . '
'; $output .= '
' . t('Users with the Administer blocks permission can create different custom block types, each with different fields and display settings, from the Custom block types 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 Field UI module help.', array('!types' => \Drupal::url('custom_block.type_list'), '!field-ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '
'; $output .= '
' . t('Creating custom blocks') . '
'; $output .= '
' . t('Users with the Administer blocks permission can add custom blocks of each of their defined custom block types. Created custom blocks are then listed on the Blocks administration page.', array('!blocks' => \Drupal::url('block.admin_display'), '!block-add' => \Drupal::url('custom_block.add_page'))) . '
'; $output .= '
'; return $output; case 'custom_block.list': $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 'custom_block.type_list': $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_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); } } /** * 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 'Body' * * @return array() * Body field instance. */ function custom_block_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'); 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; }