Hot answers tagged

3

Use QueryAggregateInterface::execute: $result = \Drupal::entityQueryAggregate('node') ->aggregate('nid', 'sum') ->condition('status', NodeInterface::PUBLISHED) ->execute(); The result returned is keyed by fieldname and aggregate function: $sum = $result['0']['nid_sum'];


2

The config system has switched already to events and the documentation for events describes in "My First Drupal 8 Event Subscriber" how to subscribe to a config event: https://www.drupal.org/docs/8/creating-custom-modules/subscribe-to-and-dispatch-events See also this example from the Color module: /core/modules/color/src/EventSubscriber/...


2

Normally you filter rows having all the same language, but you don't have to. So rows can have different languages. The code in the question seems to get the entity from the wrong place. See this topic for examples of different kind of rows: How to access raw data in twig template using views table format A normal views row is a ResultRow object having the ...


2

The Views list is a config entity list and these are listed override free: ConfigEntityListBuilder::load public function load() { $entity_ids = $this->getEntityIds(); $entities = $this->storage->loadMultipleOverrideFree($entity_ids); // Sort the entities using the entity class's sort() method. // See \Drupal\Core\Config\Entity\...


2

Based on the comments to the question, I extended the EntityReferenceEntityFormatter class and modified one part in the viewElements method (the rest is the same): $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId()); $elements[$delta] = $view_builder->view($entity, $view_mode, $entity->language()->getId(...


2

Drupal textfield widget can only be applied to string fields. https://git.drupalcode.org/project/drupal/blob/8.7.4/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php#L9 However it's not a big deal to alter its definition and make it support long strings. /** * Implements hook_field_widget_info_alter(). */ function ...


1

The example in the documentation link seemed to cause confusion. Simply set your values in an associative array and use set/get storage. $vals = [ 'name' => 'bob', 'age' => 50 ]; // save the data. $form_state->setStorage($vals); // retrieve the data $vals = $form_state->getStorage(); $str = $vals['name'] . ' is ' . $vals['age'] . ' years ...


1

I was able to reproduce your issue in a fresh Drupal 8.7.5 installation. I reported the issue in Drupal core issue tracker. Also, here are a screenshot in which French Views names are displayed in an English interface:


1

While the above API approaches are recommended, here's one more raw approach that can be useful for some cases. In this case, it adds an SQL index to a base field for the MySQL/MariaDB database engine: /** * Add SQL index on published_date base field */ function MY_MODULE_update_8010(&$sandbox) { // Add index // ALTER TABLE $table ADD INDEX $...


1

Just found this old post while debugging the same issue. Adding my fix in case other hit it too.. The problem I ran into using the sample code was this line: // Do paging. $query->range(20, 10); I since I only had a few records in my database, there wasn't 20+ records, the total count was correct, but couldn't page that far. Updating to: // Do paging....


1

Finally, I was able to resolve it by using the module handler "shs_term_data_response". Like below function YourModuleName_shs_term_data_response_alter(&$content, $context) { $termList = json_decode($content); $filteredList = array(); /..your logic to modify $termList and push it to new array.../ $content = json_encode($filteredList); } Hope ...


1

I ended up doing this: Created a new content type called "profile picture" Gave this content type an image field Loaded a bunch of profile pictures Added a node reference field to my user so i can select one of the profile picture nodes. And then finally installed and used this: https://www.drupal.org/project/entity_reference_views_select


1

The user ID is saved on the store when it's created. Therefore you can load it with code similar to the following one. $store = \Drupal::entityTypeManager()->getStorage('commerce_store')->loadByProperties(['uid' => \Drupal::currentUser()->id()]); That will load the store based on the currently logged-in user.


1

The code from your question should work in a hook_install(). But you need a lot more configuration for a content type, which you can create the easiest way in UI. See the comment of @Hudri. Then export the configuration to the config folder of your module, see Organizing config for use with a module


1

Your problem is here: use Drupal\node\Entity\Node; use Drupal\taxonomy\Entity\Term; use Drupal\views\ViewExecutable; use Drupal\views\Views; use Drupal\Core\Render; $nid = 1; $entity_type = 'node'; $view_mode = 'teaser'; $builder = \Drupal::service('entity_type.manager')->getViewBuilder($entity_type); $storage = \Drupal::service('entity.manager')->...


1

Many problems in Drupal can be solved in more than one way. This is also one of them. One way might be to use the Avatar Kit module. Another might be to create a Select field with options linking to some images you uploaded to the files folder or similar. You'd probably have to do some custom formatting if you wanted to display the options as images, and ...


1

Just to add to prkos's excellent accepted answer, I found that once I configured my website according to his instructions, if I really wanted to let end users use /fr/ language path prefixes, thereby making pages accessible without full-site switching at paths like /fr/node/1, I could do so via the following .htaccess / mod_rewrite rule: RewriteRule "^fr/(.*...


Only top voted, non community-wiki answers of a minimum length are eligible