8 – How to get drupal to check for a twig template in the active theme folder before checking the module folder?

I’m developing a contrib module for Drupal 8 that sends email notifications to group members when new content has been posted in groups they have subscribed to. The module defines some new view modes for nodes and comments. It then uses these new view modes to render the contents of the emails it sends out. The module defines a theme hook suggestion for each view mode and supplies a twig template for each view mode.

It works fine as is. The twig templates from within the module are utilized without a problem. What I’m not understanding is why copies of these templates placed within the active theme are not utilized. I’m familiar with the process of copying an existing twig template into a theme to be modified. But no matter what I do the template from the module is always used in this case. It was my understanding Drupal searches for suitable twig templates in the theme first and then works backward but perhaps my module is missing something.

Here are code samples for more details.

Define the view mode for comments – in modules/contrib/group_subscription/config/install/core.entity_view_mode.comment.group_subscription_immediate

langcode: en
status: true
dependencies:
  module:
    - comment
id: comment.group_subscription_immediate
label: 'Group Subscription Immediate (comment)'
targetEntityType: comment
cache: true

Define the theme hook suggestion – in modules/contrib/group_subscription/group_subscription.module

/**
 * Implements hook_theme()
 */
function group_subscription_theme($existing, $type, $theme, $path) {
  return (
    'comment__group_subscription_immediate' => (
      'base hook' => 'comment',
    )
  );
}

/**
 * Implements hook_theme_suggestions_comment_alter()
 */
function group_subscription_theme_suggestions_comment_alter(array &$suggestions, array $variables) {
  if ($variables('elements')('#view_mode') == 'group_subscription_immediate') {
    $suggestions() = 'comment__group_subscription_immediate';
  }
}

Please let me know if there is anything else I can provide to help me figure this out. I’ve been working with Drupal for years but am still relatively new to D8 and this is my first attempt at creating a module to give back. Thanks in advance!

theming – How to add class to all text inputs in Drupal 8?

You can do it using template_preprocess_form_element something like:

use DrupalComponentUtilityHtml;
function (YOURTHEME)_preprocess_form_element(&$variables) {
  $input_types = ('search', 'textfield', 'password');
  $type = $variables('element')('#type') ?? NULL;
  if (in_array($type, $input_types)) {
    $variables('element')('#attributes')('class')() = Html::cleanCssIdentifier('form__text');
  }
}

Update
If the below doesn’t work try the following using hook_preprocess:

/**
 * Implements hook_preprocess().
 */
function (YOURTHEME)_preprocess(&$variables, $hook) {
  if ($hook == 'input') {
    $variables('attributes')('class')() = Html::cleanCssIdentifier('form__text');
  }
}

views – PHP error in the log after PHP and Drupal upgrade

I got this error message in the log but not sure what is it about and how to fix it. Has anyone seen the same issue before and know how to fix it? Thank you so much!

DrupalCoreEntityEntityMalformedException: The “view” entity cannot have a URI as it does not have an ID in DrupalCoreEntityEntityBase->toUrl() (line 192 of /var/www/drupal_dev_8.8.6/core/lib/Drupal/Core/Entity/EntityBase.php)

users – how to load all nodes from node table drupal 7.x

I am looking to display in a form $form(”) of type select all nodes of type ‘class’ I use the this code

$nodes = node_load_multiple(array(), array('type' => 'class', 'status' => 1)); 
foreach($nodes as $classes){
 $values = array($classes->nid => t($classes->title));            
}

but when i pass the variable to the $form(”), it displays just the last node in the database not all of theme

the full code here

function form_user_form($form, &$form_state, $uid) {

$nodes = node_load_multiple(array(), array('type' => 'class', 'status' => 1)); 
foreach($nodes as $classes){
 $values = array($classes->nid => t($classes->title));               
}

  $form('title') = array(
      '#markup' => '<h3>User :'.$uid.'</h3>');

  $form('classe') = array(
    '#type' => 'select', 
    '#title' => "Classes",
    '#description' => "Select class ",
    '#options' => $values,
  );


  $form('date') = array(
      '#type' => 'date_popup',
      '#title' => t('Date '),
      '#description' => t('add date'),
      '#date_type' => DATE_DATETIME,
      '#date_timezone' => date_default_timezone(),
      '#date_format' => 'd-m-Y',
      '#date_increment' => 1,
      '#date_year_range' => '-30:+30', 
      '#required' => TRUE
  );

  $form('uid') = array(
    '#type' => 'hidden', 
    '#value' => $uid
  );

    $form('submit_button') = array(
      '#type' => 'submit',
      '#value' => t('valider'),
    );

  return $form;

}

authentication authorization – SSO between headless Drupal and frontend

I have a headless Drupal instance as backend and frontend in React JS. I am using Simple OAuth 2.0 for authorization and all the end points work fine with authorization. Now I have a use case where I need a User to login to frontend which happens with the simple Oauth 2.0 endpoint ‘/oauth/token’. Once the user logs in, they land to frontend home page and there is a link to backend, which if clicked should automatically log in the user to backend (Drupal site).

I have tried multiple options like login endpoints provided by JSON API, which successfully authenticate the user, creates a session in backend and sent cookie in response, which is received by React JS but couldnt be saved. DUe to this, the access to backend from frontend is always considered as unauthorized or Anonymous user request.

I tried to login user programatically too, but it lands me in ‘/contextual/render’ error for many of the pages in admin section of backend.

Please help me in creating a SSO for both backend and frontend.

Drupal 8 ckeditor about Limit allowed HTML tags and correct faulty HTML

when I active the ckeditor “Limit allowed HTML tags and correct faulty HTML” text-color not show but I added color hex and not show

views – Best Solution For Creating and Maintaining Custom Records in Drupal (8) DB

I would like to configure my Drupal site as a utility so that the following can be done:

  • Input/create records for contacts or clients
  • Be able to select these records for updates and add new data via the webform

An example would be to be able to select a contact/client from a drop-down, then submit data on the remaining form fields.

I’ve been testing the WebForms module, which works great, but am not seeing a native way of querying existing table data, then adding records for it.

Am I overlooking how this can be done via WebForms, or will I need to create a custom module to create the table(s), query and update the data, etc.?

views – How to solve this error in drupal 8.6.7, does not load the page?

I have a server with PHP version PHP 7.2.31, Ver 8.0.20 for Linux on x86_64 (MySQL Community Server – GPL), Server version: Apache / 2.4.6 (CentOS) and my application that I am trying to raise runs with the version of Drupal 8.6.7. In the last step to load the page it sends me this error, in the web browser: “The website encountered an unexpected error. Please try again later.” I already checked the configuration of the db, connections, the virtual host and I can’t find what else it can be. I attach the log with the errors it sends me when trying to load the page. I will greatly appreciate your help and responses. please !!!!

I add Log

(Mon May 25 16:56:34.555257 2020) (php7:notice) (pid 1260) (client 192.168.242.1:55561) Error: Call to a member function url() on null in /var/www/vhosts/citypremios.com.mx/themes/custom/newface/newface.theme on line 1023 #0 /var/www/vhosts/citypremios.com.mx/themes/custom/newface/newface.theme(356): generateResponseQuery->shapeSliderBySection(0, ‘Home’, ‘position’)n#1 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Theme/ThemeManager.php(287): newface_preprocess_page(Array, ‘page’, Array)n#2 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/Renderer.php(437): DrupalCoreThemeThemeManager->render(‘page’, Array)n#3 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/Renderer.php(195): DrupalCoreRenderRenderer->doRender(Array, false)n#4 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Template/TwigExtension.php(490): DrupalCoreRenderRenderer->render(Array)n#5 /var/www/vhosts/citypremios.com.mx/vendor/twig/twig/lib/Twig/Environment.php(467) : eval()’d code(114): DrupalCoreTemplateTwigExtension->escapeFilter(Object(DrupalCoreTemplateTwigEnvironment), Array, ‘html’, NULL, true)n#6 /var/www/vhosts/citypremios.com.mx/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_1299816ec68a555622066f849701c0c874fc2f5a2ed739b8030299f2845d2cb4->doDisplay(Array, Array)n#7 /var/www/vhosts/citypremios.com.mx/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array)n#8 /var/www/vhosts/citypremios.com.mx/vendor/twig/twig/lib/Twig/Template.php(411): Twig_Template->display(Array)n#9 /var/www/vhosts/citypremios.com.mx/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array)n#10 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template(‘themes/custom/n…’, Array)n#11 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/Renderer.php(437): DrupalCoreThemeThemeManager->render(‘html’, Array)n#12 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/Renderer.php(195): DrupalCoreRenderRenderer->doRender(Array, false)n#13 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(147): DrupalCoreRenderRenderer->render(Array)n#14 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/Renderer.php(582): DrupalCoreRenderMainContentHtmlRenderer->DrupalCoreRenderMainContent{closure}()n#15 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(148): DrupalCoreRenderRenderer->executeInRenderContext(Object(DrupalCoreRenderRenderContext), Object(Closure))n#16 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): DrupalCoreRenderMainContentHtmlRenderer->renderResponse(Array, Object(SymfonyComponentHttpFoundationRequest), Object(DrupalCoreRoutingCurrentRouteMatch))n#17 (internal function): DrupalCoreEventSubscriberMainContentViewSubscriber->onViewRenderArray(Object(SymfonyComponentHttpKernelEventGetResponseForControllerResultEvent), ‘kernel.view’, Object(DrupalComponentEventDispatcherContainerAwareEventDispatcher))n#18 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(SymfonyComponentHttpKernelEventGetResponseForControllerResultEvent), ‘kernel.view’, Object(DrupalComponentEventDispatcherContainerAwareEventDispatcher))n#19 /var/www/vhosts/citypremios.com.mx/vendor/symfony/http-kernel/HttpKernel.php(156): DrupalComponentEventDispatcherContainerAwareEventDispatcher->dispatch(‘kernel.view’, Object(SymfonyComponentHttpKernelEventGetResponseForControllerResultEvent))n#20 /var/www/vhosts/citypremios.com.mx/vendor/symfony/http-kernel/HttpKernel.php(68): SymfonyComponentHttpKernelHttpKernel->handleRaw(Object(SymfonyComponentHttpFoundationRequest), 1)n#21 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/StackMiddleware/Session.php(57): SymfonyComponentHttpKernelHttpKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#22 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): DrupalCoreStackMiddlewareSession->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#23 /var/www/vhosts/citypremios.com.mx/core/modules/page_cache/src/StackMiddleware/PageCache.php(184): DrupalCoreStackMiddlewareKernelPreHandle->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#24 /var/www/vhosts/citypremios.com.mx/core/modules/page_cache/src/StackMiddleware/PageCache.php(121): Drupalpage_cacheStackMiddlewarePageCache->fetch(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#25 /var/www/vhosts/citypremios.com.mx/core/modules/page_cache/src/StackMiddleware/PageCache.php(75): Drupalpage_cacheStackMiddlewarePageCache->lookup(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#26 /var/www/vhosts/citypremios.com.mx/vendor/asm89/stack-cors/src/Asm89/Stack/Cors.php(49): Drupalpage_cacheStackMiddlewarePageCache->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#27 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Asm89StackCors->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#28 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): DrupalCoreStackMiddlewareReverseProxyMiddleware->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#29 /var/www/vhosts/citypremios.com.mx/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): DrupalCoreStackMiddlewareNegotiationMiddleware->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#30 /var/www/vhosts/citypremios.com.mx/core/lib/Drupal/Core/DrupalKernel.php(693): StackStackedHttpKernel->handle(Object(SymfonyComponentHttpFoundationRequest), 1, true)n#31 /var/www/vhosts/citypremios.com.mx/index.php(19): DrupalCoreDrupalKernel->handle(Object(SymfonyComponentHttpFoundationRequest))n#32 {main}, referer: http://192.168.242.137/en/admin/reports/updates/update

Drupal 8 Serialization of ‘Closure’ is not allowed

I am getting Exception: Serialization of 'Closure' is not allowed in serialize() (line 14 of core/lib/Drupal/Component/Serialization/PhpSerialize.php). error on .../checkout/ID/order_information page after submitting payment details for Review. I have tried for try/catch block but it seems it never going to catch block but always give this fatal error (If I unchecked My billing information is the same as my shipping information. checkbox in Payment information form). I am using my custom payment method module for payment, does it relevant to above error, than anyone can suggest where should I look?

For content, what are the differences between nodes and terms in Drupal 9?

Here are the differences I have identified between terms and nodes so far.

Hierarchical (tree) structure

  • Taxonomy terms are hierarchical within a vocabulary by default. This can be used to provide a menu automatically with modules like Taxonomy Menu or Hierarchical Taxonomy Menu.
  • Nodes can be given a hierarchical structure in a menu (the menu contains the hierarchy), but the nodes themselves cannot be ordered in a hierarchy without some kind of custom system relying on entity references.

Revisioning

  • Nodes have a revisioning UI and you can easily roll back to previous versions.
  • Taxonomy terms have revision tracking enabled by default but there is no UI available yet. This will change someday.

Menu support on the edit page

  • Nodes can easily be added to a menu on the edit page.
  • To add a term to the menu, you have to create the term first and then manually create a link on the menu you want to add the link to.

Authoring information + promotion options

  • Nodes offer “Authoring information” to change the node author and/or publishing date; taxonomy terms do not provide a UI for this.
  • Nodes have a UI option to promote content to the front page and to keep it a sticky at the top of lists. Taxonomy terms don’t provide this out-of-the-box, but their display can be customized with Views and they have built-in support for hierarchies, so they don’t need sticky at the top of lists.