Drupal planet

Tous nos billets sur le thème Drupal planet

Render programmatically a unique field from a node or an entity with Drupal 8

It may sometimes be necessary to render a single field of a content or entity. For example, for a simplified display of contents relating to the content consulted, the use of specific fields in other contexts, etc. Obtaining programmatically the rendering of a field may be problematic for the Drupal 8 cache invalidation system, since the resulting render array would not contain the cache tags of the source entity. Let's take a look at some solutions available to us.

Token and chained entities on Drupal 8

The token module is one of these essential modules on any Drupal 8 project. It allows you to use tokens in certain input fields, whether configuration or content, to target the value of one entity field. Many modules use it to allow users or site builder to provide dynamic value without the need for coding.

Let's see how to access the content's values from these tokens, but also to the values ​​indirectly associated with these contents, from Entity reference fields.

Introduction to Protected file module on Drupal 8

Drupal 8 has several solutions and methods to manage access rights on each elements included in a content, and this in a very granular way. Enabling view or edit access on some field included in a content type can be achieved very simply, with a few lines of code, or with the Field Permissions module. We can use this module to allow certain roles to view or update a particular field.

Create an action for custom mass updates with Drupal 8

Drupal 8 makes it possible to carry out certain mass actions on the site's contents, such as publishing or unpublishing massively contents, positioning them at the top of lists, etc. It may be useful to provide to certain user profiles some customized actions related to the specificities of their site, such as highlighting certain taxonomy terms, changing the value of a specific field, and thus avoiding heavy and tedious update operations to users on each of the content to be modified.

Using the Drupal 8 Cron API to generate image styles

We saw in a previous post how we could automatically generate the image styles defined on a site for each uploaded source image. We will continue this post for this time to carry out the same operation using the Cron API of Drupal 8, which allows us to desynchronize these mass operations from actions carried out by users, and which can therefore penalize performances.

Translate programmatically with Drupal 8

Drupal 8, natively multilingual, offers a GUI to be able to translate both the site configuration (field's label, view's title, etc.) and the contents themselves. But we sometimes need to translate programmatically contents  or configurations, particularly in the context of a website factory to generate such a multilingual site.

Discover some examples to help us translate on the fly both configurations and contents. The examples below assume that we have an original content in French and that we wish to associate their English translation.

Introduction to Drupal 8 module : Permissions by field

The powerful access control system provided by Drupal 8 and permissions can prove to be a decisive criterion for choosing Drupal. This system is the basis of modules as Organic Group or Domain access, which respectively implement groups within the same site and implement a virtual multi-site architecture. The Permissions by field module allows us to control access to contents of a Drupal site in several generic methods, relying on the power of Entity Reference and the Drupal Field API, and to be able to delegate complex management access rights to content publishers according to their needs. Discover this module and the different possible use cases.