New answers tagged

0

Figured it out! Took a few steps: I created a View of type: Order Item. Added my custom fields to that view (Job Title, etc). Added a Contextual Filter "Order item: ID". Provide Default Value: Content ID from URL. I created a Viewfield on each of my Order Item Types, using the View I created in the previous step. I went to /admin/commerce/config/order-item-...


0

It seems that the previous answer was missing a small detail: the information about the view needs to be wrapped into an array with key 'view' llike following: $fields['user'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('User account')) ->setDescription(t('The user account this profile is connected to')) ->setSetting('...


1

Pager is known within the "views-view.html.twig" file: /core/modules/views/templates/views-view.html.twig If you are using a contributed or custom theme you can override that file and move the pager output where you'd like. So your new file would live here: /themes/custom/MY_THEME/templates/views-view.html.twig" for example. As near as I can tell there's ...


2

You can disable that module to return to the more traditional line-by-line error output globally, or hook into it programatically form-by-form: function MODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'foo_form') { $form['#disable_inline_form_errors'] = TRUE; } }


0

Just add a complement to the answers for D8 Place the block Exposed form: search_content-page_1 a second time, now in the region Content above the block Main page content and configure the visibility to show only on pages with the path /search/content. You need to set to YES in you page views in "advanced" tab "Exposed form in block" If you try that ...


0

I found this thread, seems like it could be a solution to this. You first need a config schema for your theme. See test_basetheme.schema.yml and friends. That defines the structure for your config. All the default keys are defined in the theme_settings base type already, so if you have no additional settings, you just do this in themes/mytheme/config/...


0

An array with 'type' => 'teaser' is specifying a field formatter, but you probably don't have a field formatter with this name. You need to add the view mode (display mode) as string argument to view():. $variables['custom_display_mode'] = $variables['node']->get('field_gallery') ->view('teaser'); For more info see How to apply a Field ...


0

The complexity with Toolbar removal is that not only markup in page_top must be removed, but also classes added to the <body>. The code below allows to add $settings['hide_admin_toolbar'] = TRUE; to your settings.local.php and remove both Toolbar markup and classes. /** * Implements template_preprocess_html(). */ function MYTHEME_preprocess_html(&...


0

Couple of problems. But the main two are: In Drupal 8, you need to call $.each() on $.once() In Drupal you don't need to call $.on() on elements. The combination of Drupal.behaviors and $.once() achieves the same goal. So your code should be something like: $(".navbar-collapse", context).once('myMainMenu').each(function () { // Do stuff here });


0

Found this answer really helpful, function my_module_entity_form_display_alter(&$form_display, $context) { if($context['entity_type'] == 'user' && $context['bundle'] == 'user'){ $user = \Drupal::currentUser(); if(!in_array('administrator', $user->getRoles())){ $storage = \Drupal::service('entity_type.manager')->getStorage('...


0

function MYTHEME_preprocess_html(&$variables) { $current_path = \Drupal::service('path.current')->getPath(); $path_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path); $is_edit = strpos($path_alias, '/edit'); if ($is_edit !== false) { $edit_css_classname = $variables['node_type'].'-edit'; $variables['attributes']['...


0

You can probably add a validation pattern to the email address and block a list of email addresses for submitting the form. Or you need to create a custom module.


0

As Kevin already mentioned: it can be done using 'composer-patches' in a similar way to patching a Drupal module. The mentioned patch contained more than I wanted to patch, so I downloaded the patch and added it to a local 'patches' directory. Also, the patch uses a path that starts at 'libraries', while the patch configuration starts one level deeper. So ...


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/...


0

You didn't specify if you wanted the library served via a CDN, but for a lot of people that might be the case. Here's an example with Fontawesome (webfont icon library). This is from a theme, but the principle is exactly the same with a module. mytheme.libraries.yml: [...] fontawesome: js: "//kit.fontawesome.com/1abc23d4ef.js": { type: external } ...


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 ...


0

The section of migrate_plus.migration.mysite_user.yml that reads this: roles: plugin: migration_lookup migration: d7_user_role source: roles has to be edited by switching "d7_user_role" for the id of your user role migration, which in your case is "mysite_role" roles: plugin: migration_lookup migration: mysite_role ...


0

Great explanation, what I did was simpler and dirtier by putting in the css display: none. But I should try your suggestion. What I think drupal will be necessary to separate the types of links to be able to use them in different ways in different places. I think the design is for a web design older than how the card links is implemented which is a more ...


0

There are many approaches in aliasing and routing, but I think splitting the task between both is the most effective: Add an internal node route for the second view mode: mymodule.custom_node: path: '/node_custom/{node}' defaults: _entity_view: 'node.custom_view_mode' requirements: _access: 'TRUE' Then change the source path to /node_custom/...


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 ...


0

I had to change my overall approach to the problem, but managed to solve the serialising problem by using two additional modules: https://www.drupal.org/project/views_field_view https://www.drupal.org/project/rest_export_nested The description of the REST Export Nested explains everything. The only thing that might provide problematic is the performance ...


1

Is the redirect from /user/logout to /user/login?destination=/ No, the normal behavior is to redirect to the frontpage. You probably have a module installed which issues a second redirect when the logged out user doesn't have access to the frontpage. How is the user logout process supposed to work? This is the core controller as example: UserController:...


0

with https://www.drupal.org/project/menu_link_attributes you can add a css classes to each menu item so that you can theme it as needed.


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\...


0

For me adding dependenciesin libraries.yml did not worked, I am using drupal 8.x version. Below is working solution for me In your theme file, say your theme name is "abc" then you will have a file "abc.theme", add following code in file. assuming your page alias path is "abcde" where you want to add the dialog box function abc_page_attachments_alter(&$...


0

Captcha is a valid form element if you have captcha module installed. $form['tabs']['upload']['captcha'] = [ '#type' => 'captcha', '#captcha_type' => 'captcha/Math', ] if you want to use recaptcha, the type is '#captcha_type' => 'recaptcha/reCAPTCHA',


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(...


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:


0

None of the relations information is stored in C, so when you have C views it can't show relations info out-of-box. Usually the way to show the "Child" for a "Parent" node is by using the Contextual filter for the Entity Reference field with the "provide default value" and "Content ID from URL" options. In your case A is a child of B, and B is a child of C....


0

Thanks to the comment above I was able to find a solution. This function allows to access three fields within a paragraph (term reference field, text field, boolean field). public function viewElements(FieldItemListInterface $items, $langcode) { $element = []; // Render each element as markup in case of multi-values. foreach ($items as $delta => $...


0

You may want to cache your response with CacheableRedirectResponse


0

Command "drush entity-updates" has been removed from v 8.7.0 See https://www.drupal.org/node/3034742 Starting with 8.7.0, Drupal core no longer provides support for automatic entity updates. Whenever an entity type or field storage definition needs to be created, changed or deleted, it has to be done with an explicit update function as provided by the ...


0

This has been bumped up to the homepage. To make the comment of @Clive more clear, you can attach page attachments via #attached to any theme or render element (#theme, #type, #markup) and it will bubble up to page level when rendered: $variables = [ '#theme' => 'page_partner', '#attached' => [ 'html_head' => [ [ [ '#...


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 $...


0

Also, check out the Webform Content Creator module. This module provides the ability to create nodes after submitting webforms, and do mappings between the fields of the created node and webform submission values.


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....


0

Right now your rrule condition is a singleton of its "OR" group. You need to add all the other conditions to an "AND" group and place that group as a sibling to the rrule condition in the "OR" group.


0

After working with JDev518 on this we discovered this was a permissions issue with paragraphs. Although this should have worked as is, we ended up installing Paragraph Type Permissions" and assigning specific permissions to create/edit/view the paragraph fields in question for anonymous. This "forced" the permission check to work and started including the ...


0

Refer below sample code function mymodule_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) { $field_name = $context['items']->getName(); $field = FieldConfig::loadByName('node', 'page', $field_name); if ($field) { $element['#prefix'] = 'hello world'; } }


0

If you have already created a webform then you can follow thi step Open this url /admin/structure/webform (Structure -> Webform) Click on "Build" in OPERATIONS column Click on "+Add element" button, there will be seen a list form element, you can select captcha from available element


0

The best way to alter view field and change the value or change the format of the field. You can use this snippet. /** * Implements TEMPLATE_preprocess_views_view_field(). */ function MODULENAME_preprocess_views_view_field(&$vars) { if (isset($vars['view']) && ($vars['view']->id() == 'VIEW_MACHINE_NAME') && ($vars['view']->...


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


0

Couldn't find an answer using Rules, and ended up adding some code: function my-module_comment_insert(Drupal\Core\Entity\EntityInterface $entity) { // Get NID and load Node $nid = $entity->get('entity_id')->target_id; $node = \Drupal\node\Entity\Node::load($nid); } From there I can use $node->get('field_something'). Of course if it's an ...


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.


0

@mcaleaa answer helped me on an acquia based site. To fix it I commented out the following lines in development.services.yml: parameters: http.response.debug_cacheability_headers: true


0

The Accepted answer is good, but for anybody that would like to use the New DrupalDateTime here are few examples. I. If you have a date and want format it, just pass it to the static method of the class (DrupalDateTime) as follows. You can replace the string with your date variables. Below shows both using the static version and non static version of ...


0

Here is Answer, in your .theme file add below code function themename_preprocess_comment(&$variables) { $date = $variables['comment']->getCreatedTime(); $variables['created'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $date); $variables['submitted'] = t('@author', array('@author' => $variables['author'], '!datetime' => '' . ...


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


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'];


Top 50 recent answers are included