' . 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('!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')) . '
'; $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 'block_content.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 block_content_theme($existing, $type, $theme, $path) { return array( 'block_content_add_list' => array( 'variables' => array('content' => NULL), 'file' => 'block_content.pages.inc', 'template' => 'block-content-add-list', ), ); } /** * Implements hook_entity_type_alter(). */ 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['block_content']->get('translation'); $translation['block_content'] = TRUE; $entity_types['block_content']->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. */ function block_content_add_body_field($block_type_id, $label = 'Body') { // Add or remove the body field, as needed. $field_storage = FieldStorageConfig::loadByName('block_content', 'body'); $field = FieldConfig::loadByName('block_content', $block_type_id, 'body'); if (empty($field_storage)) { $field_storage = entity_create('field_storage_config', array( 'field_name' => 'body', 'entity_type' => 'block_content', 'type' => 'text_with_summary', )); $field_storage->save(); } if (empty($field)) { $field = entity_create('field_config', array( 'field_storage' => $field_storage, 'bundle' => $block_type_id, 'label' => $label, 'settings' => array('display_summary' => FALSE), )); $field->save(); // Assign widget settings for the 'default' form mode. 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('block_content', $block_type_id, 'default') ->setComponent('body', array( 'label' => 'hidden', 'type' => 'text_default', )) ->save(); } return $field; }