Skip to content
Snippets Groups Projects
Commit 7e4221fe authored by Mahmoud Zayed's avatar Mahmoud Zayed
Browse files

Cleanup and add readme.md

parent f6c217f6
No related branches found
Tags 1.0.0-alpha2
No related merge requests found
# Section Library
Allows saving the section as a template, so we can reuse it again in other pages or same pages as a duplicate, whether the section blocks are generic or inline the module differentiate between them and builds new instances for the inline blocks.
### FEATURES
Content Based: The content editor (Layout Manager) can save any created section(s) to the library to reuse it over and over.
Build single, or multiple sections as a template: Save individual section or combine multiple sections (or all sections on the page) as a template.
### REQUIREMENTS
Drupal Core Layout Builder module.
### INSTALLATION
Install like any other contributed Drupal module.
See: https://www.drupal.org/docs/8/extending-drupal-8/installing-contributed-... for further information.
### RECOMMENDATION
You can use this module with Optional modules like:
Layout Builder Modal: Replace the default off-canvas dialog with modal, so it will show more modern library.
### SIMILAR MODULES
The key difference between this module and the Layout Builder Library module that the latter builds a full page template and is config based. The Section Library is content based so the content editor can create templates on the fly without import/export configs, also it builds templates for the section or multiple combined sections (page) templates.
There is no overlapping between the two modules and you can use both at the same time.
Section Library
{
"name": "drupal/section_library",
"description": "Create reusable templates for single or multiple sections at the layout builder.",
"type": "drupal-module",
"keywords": ["Drupal", "custom", "section", "library" ,"Layout Builder"],
"license": "GPL-2.0+",
"description": "section library.",
"version": "dev-master",
"keywords": ["Drupal", "section", "library", "template", "Layout Builder"],
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Mahmoud Zayed",
"homepage": "https://www.drupal.org/u/mahmoud-zayed",
"role": "Maintainer"
}
],
"homepage": "https://www.drupal.org/project/section_library",
"support": {
"issues": "https://www.drupal.org/project/issues/section_library",
"source": "http://cgit.drupalcode.org/section_library"
},
"require": {
"drupal/core": "^8.7.7 || ^9"
}
......
{
"name": "section_library",
"description": "Section library.",
"author": "Mahmoud Zayed & Aaron Christian",
"description": "Create reusable templates for single or multiple sections at the layout builder.",
"author": "Mahmoud Zayed",
"version": "1.0.0",
"scripts": {
"css:compile": "node-sass --importer node_modules/node-sass-magic-importer/dist/cli.js scss/ --output-style expanded -o css/",
......
name: 'Section Library'
description: 'Section library.'
description: 'Create reusable templates for single or multiple sections at the layout builder.'
type: module
core: 8.x
core_version_requirement: ^8 || ^9
......
......@@ -12,9 +12,6 @@ use Drupal\Component\Serialization\Json;
* Implements hook_element_info_alter().
*/
function section_library_element_info_alter(array &$types) {
// $types['layout_builder']['#pre_render'] = [
// [\Drupal\section_library\Element\LayoutBuilder::class, 'preRenderSectionLibrary'],
// ];
$types['layout_builder']['#pre_render'][] = '_section_library_layout_builder_pre_render';
}
......@@ -30,7 +27,7 @@ function _section_library_layout_builder_pre_render($element) {
continue;
}
// New sections.
// Add import from library link to the new section.
if (isset($section['link']) && isset($section['link']['#url'])) {
$params = $section['link']['#url']->getRouteParameters();
$url_options = [
......@@ -76,7 +73,7 @@ function _section_library_layout_builder_pre_render($element) {
),
];
}
// Configure section.
// Add save to library link to the built section.
elseif (isset($section['configure']) && isset($section['configure']['#url'])) {
$params = $section['configure']['#url']->getRouteParameters();
// Pop the last item to add the link before it.
......@@ -138,6 +135,7 @@ function _section_library_layout_builder_pre_render($element) {
$element['layout_builder'] = $sections;
// Attach the library.
$element['#attached']['library'][] = 'section_library/section_library';
}
......
......@@ -16,7 +16,7 @@ use Drupal\Core\Render\Markup;
use Drupal\file\Entity\File;
/**
* Defines a controller to choose a new block.
* Defines a controller to choose a section from library.
*
* @internal
* Controller classes are internal.
......
......@@ -13,10 +13,6 @@ use Drupal\user\EntityOwnerInterface;
*/
interface SectionLibraryTemplateInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
/**
* Add get/set methods for your configuration properties here.
*/
/**
* Gets the Section library template creation timestamp.
*
......
......@@ -5,7 +5,7 @@ namespace Drupal\section_library\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Section library entity entities.
* Provides Views data for Section library template entities.
*/
class SectionLibraryTemplateViewsData extends EntityViewsData {
......@@ -15,8 +15,6 @@ class SectionLibraryTemplateViewsData extends EntityViewsData {
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
......
......@@ -14,7 +14,7 @@ use Drupal\section_library\Entity\SectionLibraryTemplate;
use Drupal\file\Entity\File;
/**
* Provides a form for configuring a layout section.
* Provides a form for adding a section to the library.
*
* @internal
* Form classes are internal.
......@@ -47,7 +47,7 @@ class AddSectionToLibraryForm extends FormBase {
protected $delta;
/**
* Constructs a new ConfigureSectionForm.
* Constructs a new AddSectionToLibraryForm.
*
* @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
* The layout tempstore repository.
......@@ -114,13 +114,6 @@ class AddSectionToLibraryForm extends FormBase {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
......
......@@ -14,7 +14,7 @@ use Drupal\section_library\Entity\SectionLibraryTemplate;
use Drupal\file\Entity\File;
/**
* Provides a form for configuring a layout section.
* Provides a form for adding a template to the library.
*
* @internal
* Form classes are internal.
......@@ -47,7 +47,7 @@ class AddTemplateToLibraryForm extends FormBase {
protected $delta;
/**
* Constructs a new ConfigureSectionForm.
* Constructs a new AddTemplateToLibraryForm.
*
* @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
* The layout tempstore repository.
......@@ -114,13 +114,6 @@ class AddTemplateToLibraryForm extends FormBase {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
......
......@@ -23,7 +23,6 @@ class SectionLibraryForm extends ContentEntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
$status = $this->entity->save();
// kint($status);die;
$label = $this->entity->label();
switch ($status) {
......@@ -33,8 +32,14 @@ class SectionLibraryForm extends ContentEntityForm {
]));
break;
case SAVED_UPDATED:
$this->messenger()->addMessage($this->t('%label has been updated.', [
'%label' => $label,
]));
break;
default:
$this->messenger()->addMessage($this->t('%label added to section library.', [
$this->messenger()->addMessage($this->t('%label saved to section library.', [
'%label' => $label,
]));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment