New answers tagged

1

Objective: Show upcoming events, then past events. The simplest way to implement this entirely through the View UI is to add a second display to the view. Basic steps Create the main view display. Configure the events to display as you like. Set to sort by upcoming events, and filter so that only upcoming events are displayed. Add an Attachment display. ...


0

case 'ec_topics': $count = count($entity->field_ec_subtopics); if ($count == 1){ $values = $entity->field_ec_subtopics->getValue(); $content = $values[0]['value']; $items = explode(PHP_EOL,$content); $count = count($items); $entity->field_ec_subtopics = $items; } $entity->...


1

hook_pathauto_pattern_alter() is only invoked when: The entity has a path field Pathauto processing is enabled For entities that support revisions, the entity is using the default revision A default pattern has been set for that entity $entity->toUrl()->getInternalPath() doesn't throw a EntityMalformedException, UndefinedLinkTemplateException, or ...


1

Per the Drupal coding standards, the closing php tag should be omitted. The PHP Code Tags section of the coding standards (as well as this stackoverflow answer) give a good overview of why it's a good practice to omit them in general: Removing it eliminates the possibility for unwanted whitespace at the end of files which can cause "header already sent&...


0

In this approach, the hook is fired for all forms To avoid extra firing of the hook, use this approach (module name and form id) function MYMODULE_user_register_form_alter(&$form, Drupal\Core\Form\FormStateInterface $form_state, $form_id){ //do your alteration }


3

Using redirects with $response->send() like this used to work: $response = new RedirectResponse($url); $response->send(); But, this no longer works in Drupal 9.2. Also, it breaks JSON:API in versions before 9.2. The correct way to do it is described in detail in this excellent answer. Basically, you need to create your own custom http_middleware ...


0

Since this is still high on the list of search results: in Drupal 9 (unsure of which versions this , the index property of each view row determines the order, not the array of rows itself. So, if you get the row objects ordered to your liking, you can do something like this: // Optionally set the array keys to start at zero and count up first. $...


0

Menu links are entities themselves. Unless you've done something special to create a new menu link entity type, they will be entity type menu_link_content. You can use hook_ENTITY_TYPE_presave() to make your change. Note that when you see an all-caps section of a hook, that means it should be replaced by a specific value, e.g. hook_node_presave() or ...


Top 50 recent answers are included