Philipp Zedler
  • Member for 4 years, 7 months
  • Last seen this week
How to print custom date format in Twig?
17 votes

First, create the custom date format my_custom_date_format in the configuration section of the drupal admin. Second, use the format_date Twig filter, like here: {{ node.created.value|format_date('...

View answer
How load only some node fields?
4 votes

I did some profiling with a query of 100,000 nodes, fetching the field myfield from all nodes of type mybundle. Good: A dynamic query with addField() $connection = \Drupal::database(); $query = $...

View answer
Trigger an action programmatically
Accepted answer
2 votes

This works: $action = \Drupal::entityTypeManager() ->getStorage('action') ->load('send_mail'); if ($action) { $action->execute($entity); }

View answer
$user-> removeRole('administrator') doesn't remove role
1 votes

Looking at the Drupal code, it's absolutely clear that removeRole requires not the name but the id of the role: https://github.com/drupal/drupal/blob/8.4.x/core/modules/user/src/Entity/User.php#L188 ...

View answer
Errors from custom FieldItemList::getConstraints() displayed next to every single property
Accepted answer
0 votes

We can place the errors with three modifications in the widget class. First, we add the empty form element non_field_errors we can attach the errors to. class YearRangeWidget extends WidgetBase { ...

View answer
Change article date format
0 votes

To be sure that I change only the characters of the date but not any surrounding HTML elements, I use the following hook: function [theme_name]_preprocess_field(array &$variables) { if ($...

View answer
Return a 404 when a view pane in a page manager page has no result?
0 votes

@Andrew's answer adopted to Drupal 8: use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Implements hook_views_pre_render(). */ function mymodule_views_pre_render(&$view) {...

View answer
How to remove default 'search' text form search form
0 votes

An alternative to altering the template variables is to override the template file. Switch on template debug to see what template is used in the HTML comments. Copy that template to your theme ...

View answer