Chris@0: moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#'; Chris@0: $output = ''; Chris@0: $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']) . '
'; Chris@0: $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')]) . '
'; Chris@0: return $output; Chris@0: Chris@0: case 'entity.block_content_type.collection': Chris@0: $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')]) . '
'; Chris@0: return $output; Chris@0: Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements hook_theme(). Chris@0: */ Chris@0: function block_content_theme($existing, $type, $theme, $path) { Chris@0: return [ Chris@0: 'block_content_add_list' => [ Chris@0: 'variables' => ['content' => NULL], Chris@0: 'file' => 'block_content.pages.inc', Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements hook_entity_type_alter(). Chris@0: */ Chris@0: function block_content_entity_type_alter(array &$entity_types) { Chris@0: /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ Chris@0: // Add a translation handler for fields if the language module is enabled. Chris@0: if (\Drupal::moduleHandler()->moduleExists('language')) { Chris@0: $translation = $entity_types['block_content']->get('translation'); Chris@0: $translation['block_content'] = TRUE; Chris@0: $entity_types['block_content']->set('translation', $translation); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds the default body field to a custom block type. Chris@0: * Chris@0: * @param string $block_type_id Chris@0: * Id of the block type. Chris@0: * @param string $label Chris@0: * (optional) The label for the body instance. Defaults to 'Body' Chris@0: * Chris@0: * @return \Drupal\field\Entity\FieldConfig Chris@0: * A Body field object. Chris@0: */ Chris@0: function block_content_add_body_field($block_type_id, $label = 'Body') { Chris@0: // Add or remove the body field, as needed. Chris@0: $field = FieldConfig::loadByName('block_content', $block_type_id, 'body'); Chris@0: if (empty($field)) { Chris@0: $field = FieldConfig::create([ Chris@0: 'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'), Chris@0: 'bundle' => $block_type_id, Chris@0: 'label' => $label, Chris@0: 'settings' => ['display_summary' => FALSE], Chris@0: ]); Chris@0: $field->save(); Chris@0: Chris@0: // Assign widget settings for the 'default' form mode. Chris@0: entity_get_form_display('block_content', $block_type_id, 'default') Chris@0: ->setComponent('body', [ Chris@0: 'type' => 'text_textarea_with_summary', Chris@0: ]) Chris@0: ->save(); Chris@0: Chris@0: // Assign display settings for 'default' view mode. Chris@0: entity_get_display('block_content', $block_type_id, 'default') Chris@0: ->setComponent('body', [ Chris@0: 'label' => 'hidden', Chris@0: 'type' => 'text_default', Chris@0: ]) Chris@0: ->save(); Chris@0: } Chris@0: Chris@0: return $field; Chris@0: }