Repository URL to install this package:
|
Version:
1.0.20 ▾
|
Atoms is meant to give developers an easy and quick way to add small pieces of content to a site that an administrator can then freely change as they see fit. Of course there are many options for content already like nodes and other entities to fill out a page, but these are usually overkill when just talking about a text in a custom form or similar.
This is what Atoms is for. Very small pieces of content in places where it's usually quite bothersome to embed any other type of content entity.
For most use cases using a Atoms is as easy as calling the atom() function whenever you need it.
$build = atom('example-machine-name');
This returns a render array with all the necessary cacheability information and context menus for the Atom in question. There are also other variants for more specialized uses like atom_lazy() which works like atom() but as a lazy builder where performance might be an issue. Last we have atom_str() which just delivers a rendered string, but cacheability is lost and must be taken care of manually.
There are also Twig functions with the same names...
<p>{{ atom('example-machine-name') }}</p>
When defining new Atom you need to create a MODULE.atoms.yml file or THEME.atoms.yml which will include definitions for all the atoms needed for that module or theme. All definition files must begin with atoms: as the first line and the individual atoms beneath it.
atoms: example-machine-name: type: textfield title: Example title description: An Atom used as an example for documentation. category: Example Category group: Example group subgroup: Example group default: en: 'English test title' da: 'Dansk test titel' options: translatable: TRUE token_types: - node
Every definition starts with a unique machine name for the Atom followed by the following properties:
Provides a simple plain text field for entering short texts containing no markup.
Same as textfield, but for longer texts and provided with multiple lines for editing.
Same as textfield, but with validation for e-mail addresses.
Gives a field for entering a number integer with validation and support for mobile number input.
The field gives access to a Rich Text editor enabling the administrator to use markup for formatting. The default text format and allowed formats can be configured for all text_format fields on the Atoms settings page.
This field gives a date picker for selecting a date to be displayed in a selected Drupal date format. The default date format can be configured for all date fields on the Atoms settings page.
This field gives a date picker for selecting a date and time to be displayed in a selected Drupal date format. The default date format can be configured for all datetime fields on the Atoms settings page.
The field allows the administrator to specify an url, either internal, external or both. If internal urls are allowed it will give suggestions for nodes, but any relative url is allowed.
The field allows the administrator to specify an url, either internal, external or both and a title which together creates a link. If internal urls are allowed it will give suggestions for nodes, but any relative url is allowed.
The field allows the administrator to specify an url, either internal, external or both and a title which together creates a button. If internal urls are allowed it will give suggestions for nodes, but any relative url is allowed. The field type default to a link with the button class when rendered, but can be configured to use any other class as appropiate to the theme on the site.
This field can allow the administrator to select a single or multiple entities of a certain type using an autocomplete field.
This field can allow the administrator to select a single or multiple media entities using an autocomplete field. Sadly Drupal Core still does not support using Media Library outside of fields yet.
This field can allow the administrator to select a single icon using the icon library.
Should the need for more advanced usage of Atoms be required then it's recommended to use the AtomsViewBuilder service. Using this service you get access to ViewableAtom objects via the get() method and these are much more adjustable than simply using atom().
As a shortcut you can use atom_view() to get a ViewableAtom without having to get the AtomsViewBuilder service.
ViewableAtom objects allow you to set the following properties before rendering the Atom:
It also gives you access to lots of information useful rendering or other usage:
And lastly you have several options for rendering or other output: