moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#'; $output = ''; $output .= '

' . t('About') . '

'; $output .= '

' . t('The Custom Block module allows you to create and manage custom block types and content-containing blocks from the Custom block library page. Custom block types have fields; see the Field module help for more information. Once created, custom blocks can be placed in regions just 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.', [':block-library' => \Drupal::url('entity.block_content.collection'), ':block-content' => \Drupal::url('entity.block_content.collection'), ':field-help' => \Drupal::url('help.page', ['name' => 'field']), ':blocks' => \Drupal::url('help.page', ['name' => 'block']), ':online-help' => 'https://www.drupal.org/documentation/modules/block_content']) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating and managing custom block types') . '
'; $output .= '
' . t('Users with the Administer blocks permission can create and edit custom block types with fields and display settings, from the Block types page in the Custom block library. For more information about managing fields and display settings, see the Field UI module help.', [':types' => \Drupal::url('entity.block_content_type.collection'), ':field-ui' => $field_ui]) . '
'; $output .= '
' . t('Creating custom blocks') . '
'; $output .= '
' . t('Users with the Administer blocks permission can create, edit, and delete custom blocks of each defined custom block type, from the Blocks page in the Custom block library. After creating a block, place it in a region from the Block layout page; see the Block module help for more information about placing blocks.', [':blocks' => \Drupal::url('block.admin_display'), ':block-library' => \Drupal::url('entity.block_content.collection'), ':block_help' => \Drupal::url('help.page', ['name' => 'block'])]) . '
'; $output .= '
'; return $output; case 'entity.block_content.collection': $output = '

' . t('Blocks in the block library belong to Custom block types, each with its own fields and display settings. After creating a block, place it in a region from the Block layout page.', [':types' => \Drupal::url('entity.block_content_type.collection'), ':blocks' => \Drupal::url('block.admin_display')]) . '

'; return $output; case 'entity.block_content_type.collection': $output = '

' . t('Each block type has its own fields and display settings. Create blocks of each type on the Blocks page in the custom block library.', [':block-library' => \Drupal::url('entity.block_content.collection')]) . '

'; return $output; } } /** * Implements hook_theme(). */ function block_content_theme($existing, $type, $theme, $path) { return [ 'block_content_add_list' => [ 'variables' => ['content' => NULL], 'file' => 'block_content.pages.inc', ], ]; } /** * 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 \Drupal\field\Entity\FieldConfig * A Body field object. */ function block_content_add_body_field($block_type_id, $label = 'Body') { // Add or remove the body field, as needed. $field = FieldConfig::loadByName('block_content', $block_type_id, 'body'); if (empty($field)) { $field = FieldConfig::create([ 'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'), 'bundle' => $block_type_id, 'label' => $label, 'settings' => ['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', [ 'type' => 'text_textarea_with_summary', ]) ->save(); // Assign display settings for 'default' view mode. entity_get_display('block_content', $block_type_id, 'default') ->setComponent('body', [ 'label' => 'hidden', 'type' => 'text_default', ]) ->save(); } return $field; }