Giter VIP home page Giter VIP logo

wmcontent's Introduction

wmcontent

Latest Stable Version Total Downloads License

Adds configurable entity containers to entity types (for e.g. paragraphs)

Why?

In Drupal 7 we noticed a couple of shortcomings with the Paragraphs module (that are still not solved in Drupal 8 AFAWK).

  • Backend performance improvements: Paragraphs creates a widget within the default entity edit forms. This did not only clutter the interface when using > 10 paragraphs, the form itself would regularly become too large and break any decent PHP memory setting on submitting/saving. This module provides a separate tab for its content, instead of mixing it in with the node edit form through inline entity forms or similar solutions.
  • Frontend performance improvements: The paragraphs of an entity are loaded separately from the standard entity data, which solves memory issues when displaying a lot of entities on a page.
  • UI improvements: Features like cloning/duplication of paragraphs as well as drag and drop sorting of paragraphs become easier when not integrated in the default entity edit form.
  • More flexibility: This module allows multiple lists of paragraphs (containers) to be attached to entities, where one can limit the available entity types and bundles on a per-container basis. This allows for e.g. a Content tab and a Program tab for activity/event content types.

Installation

This package requires PHP 8.1 and Drupal 10.0 or higher. It can be installed using Composer:

 composer require wieni/wmcontent

How does it work?

Terminology

  • A container connects hosts of a certain type to children of a certain type.
  • A host is an entity with containers, e.g. a node with a paragraph container. A host can have multiple children per container.
  • A child is an entity attached to a host through a container, e.g. a paragraph. Every entity can only be attached to a single container.

Children and hosts can be entities of any type with a canonical route, implementing Drupal\Core\Entity\ContentEntityTypeInterface.

When updating a child entity, the changed time of the host entity is updated as well.

Get started

Before you begin, make sure your user role has the administer wmcontent permission. After that, you can get started by creating a new container. You can do this by going to /admin/config/wmcontent/containers or by following the Structure > WmContent > WmContent Containers menu link.

After creating the container, go to the (edit) page of a possible host entity. A new tab should have appeared with the name of the container you just created.

Clicking that link brings you to the master form, where you can add children to and edit/delete/reorder children from this host.

Displaying children

If you use Display Suite to build your pages, you can use the WmContent: Content blocks field to display the content of the children entities on a host.

You can change the way wmcontent containers are rendered by overriding the wmcontent theme implementation.

If you build your pages manually using Twig templates, you can load the children of a host using WmContentManagerInterface::getContent.

Changelog

All notable changes to this project will be documented in the CHANGELOG file.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

Distributed under the MIT License. See the LICENSE file for more information.

wmcontent's People

Contributors

akasake avatar dieterholvoet avatar ponkiwonki avatar robinhoutevelts avatar spoit avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

drupallabs

wmcontent's Issues

Content entities are not deleted when host entity is deleted

Description

When deleting an entity having content through one or more containers, the child entities are orphaned but not deleted. On sites with a lot of content, the amount of orphaned entities can build up fast and can unnecessarily increase the database size.

Expected result

Delete child entities when the host entity is deleted.

Add PHPStan to coding standard fixers

  • Add phpstan.neon config file referencing the wmcodestyle rule files (example)
  • Add phpstan analyse to the coding-standards composer script
  • Add autoload-dev entry to ensure autoloading during analysis

Improve the master form

Summary

Move custom form alters to the module or find another way to make the form look decent by default.

Motivation

In all of our projects using this module, we're altering the master form to a certain way. Without these alters, and without using our backend theme, the form looks a bit broken. We should improve the default appearance of the form on other sites and other themes.

Feature: Translatable snapshots

Summary

Context: What are Snapshots?

This module has a (undocumented #44) feature: Snapshots.
When setup you can create a snapshot of the state of your contentblocks. You can then choose to restore a page to a previous snapshot. Smells like revisions.
You can also export an existing snapshot to a base64 blob and import it to other pages or even other environments.

Our clients use it to prepare pages on staging.
Or to quickly reuse layouts without having to recreate all blocks individually (they still need to edit each block to change the text/images/...).

Here is a video to give you an idea.

snapshots.mp4

Currently editors often have pages with lots of contentblocks in their main language.
But the translated versions of those pages contain less blocks due to it not being the native language of most editors, a shortage of translators or financially not feasible to translate all pages.

We want to help our editors solve this problem by making it possible to translate snapshots using external services (DeepL, Google Cloud Translation API, ...).

Why update this module

As #44 points out, the Snapshot functionality is largely undocumented.
The module has only defined a set of interfaces and an abstract class to make it possible to implement it. Intentionally done that way to see what different solutions would pop up. Before choosing one to embed in this module as a submodule.
So far we (Wieni) have only used it twice in custom modules and both times use Drupal's serialization module to serialize contentblocks to arrays.

To provide the translation feature I talk about above we, however, need to make two changes to this module.

1๏ธโƒฃ Snapshot needs to store the original langcode

When we create a Snapshot of a host, we should store the language of that host in the Snapshot.
๐Ÿ‘‰ Add a source_langcode field to Snapshot entity type.

2๏ธโƒฃ SnapshotBuilderBase::denormalize() needs to accept the source language.

Currently the method accepts array $data, string $langcode.
So we have the serialized array of the block and know the language we need to create it in.

But it's not easy to extract the host's language from a block's serialized array.
Now Snaphots have a source_langcode we can use that value and pass it to the denormalize() method.

๐Ÿ‘‰ Pass the Snapshot's source_value to the SnapshotBuilderBase::denormalize() method.
This is being done in the SnapshotService.

$denormalized[] = new DenormalizationResult(
$builder->denormalize($block['data'], $language->getId()),
$builder
);

Add db indexes

There are some fields that are constantly being queried but have no index:

  • wmcontent_parent
  • wmcontent_parent_type
  • wmcontent_container

Clean up branches

Description

  • Clean up unused branches (check Sourcegraph to make sure the branch is not directly required in a composer.json file)
  • Switch default branch to main

fix codestyle

  • protected $child_bundles
  • array()
  • lines over 160 chars that could easily be split over multiple lines while increasing readability
  • remove comments like put it in the table, some internal values and add the operations that provide less information than the 2 lines of actual code that follow it.

2.1.0 is not compatible with Drupal 9

Description

When updating to 2.1.0 on a Drupal 9 project we see:

Uncaught Error: Interface "Symfony\Component\HttpKernel\ControllerValueResolverInterface" not found

The ValueResolverInterface got introduced in Symfony 6.2 which is only available since Drupal 10.0

Proposed solution

Update composer.json and readme to indicate the project isn't compatible with Drupal 9 anymore.
Delete the 2.1.0 tag on GitHub and Packagist.
Create a new 3.0.0 tag, to be used in Drupal 10 projects.
Recreate a new 2.2.0 tag.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.