Developer news sources aggregated
Just came across a phenomenal resource of aggregated dev focused news. Check it out at https://devurls.com/.
You're welcome :-)
Just came across a phenomenal resource of aggregated dev focused news. Check it out at https://devurls.com/.
You're welcome :-)
Drupal 10.3 uses CKEditor 41.3.1, which changed Model
to ViewModel
.
To support both Drupal 10.2 and 10.3, you can use this shim.
Make sure you have this in global.d.ts
:
Someone on my team added the following setting to check whether an environment variable was true or false:$settings['x_menu_admin_enable'] = strtolower(getenv('X_MENU_ADMIN_ENABLE')) === 'true' ? getenv('X_MENU_ADMIN_ENABLE') : FALSE;
I find that using PHPs filter_var makes this code a bit easier to parse and only calls getenv
once:
When validating an options form for a views field plugin class that extends FieldPluginBase, you need to add a `validateOptionsForm()` function and use an array for getting the value although when setting the error you don't need to include 'options':/**
* {@inheritdoc}
*/
public function validateOptionsForm(&$form, FormStateInterface $form_state): void {
I was trying to debug a Guzzle response error but the error message was fairly long and some crucial information about which specific API fields were unauthorized was missing. The Guzzle Client Exception object has some handy methods to allow reading the full message contents:
$exception->getResponse()->getBody()->getContents();
Drush 12 no longer uses the "--no-post-updates
" option in the drush updb
command. This means that you won't be able to run database updates from drush without triggering the post update hooks.
In Drupal, there's a drush entity:save
(alias esav
) command which is useful when you want to save entities in bulk.
I needed to use this command the other day to save some entities that update a field value on the entity during a presave hook. Instead of running a database update to change the data, I just triggered the update by saving the entities, e.g
drush esav your_entity_type_id 12167,12168,12169,12170,12171,12172
To save all entities of a type, you can use:
You can check the request to detect whether you're in a Drupal modal:
$request->query->get('_wrapper_format') === 'drupal_modal';
I needed to use this when embedding a block plugin within a modal form, and wanted to display the block slightly differently than it normally gets displayed.
Instead of using the ternary operator to set a value or a default if that value doesn't exist, Twig's "default" filter provides a more compact and readable way of doing so. For example:
{% set alignment = alignment ? 'pagination--' ~ alignment : 'pagination--center' %}
Becomes:
{% set alignment = 'pagination--' ~ alignment|default('center') %}
This method is from a custom entity class. The revision_id needs to match your entity's revision entity key.