vijaycs85
  • Member for 9 years, 4 months
  • Last seen this week
Print the query which is built using db_select()
20 votes

Another option is: global $theme_key; $query = db_select('block') ->condition('theme', $theme_key) ->condition('status', 1) ->fields('block'); print strtr((string) $query, $query->...

View answer
How do I enable developer/debug mode?
19 votes

Add the following line in the settings.php file. $config['system.logging']['error_level'] = 'verbose'; See Make developer tricks / tools for D8 more discoverable/obvious for more details.

View answer
Drush 8.1 Drupal 8 throws PDOException: SQLSTATE[HY000] [2002] on MAMP
11 votes

Make sure your database host setting is 127.0.0.1 instead of localhost.

View answer
How to get bundle label from entity
9 votes

If you are not sure about the $entity type, it can be: if ($entity->bundle()) { $bundle_type_id = $entity->getEntityType()->getBundleEntityType(); $bundle_label = \Drupal::...

View answer
Drupal 8 - "Implement menu links as plugins", trying to build a menu tree
Accepted answer
6 votes

You may need to render it as below: // Build the main menu links tree. if (!empty($vars['main_menu'])) { // Build links. $config = Drupal::config('menu_ui.settings'); $menu_enabled = ...

View answer
How to purge cached content every day via cache tag?
4 votes

Here is the code that flush cache on first hit of a day: public function build() { ... ... ... $this->handleCacheTag($build['#cache']['tags']); } protected function ...

View answer
Date range field misses the minutes when they are the same
4 votes

Hope you are using core date module with end date. If you are, here is my field configuration in content type: Once have the field configured with custom date format, the display seems working as ...

View answer
Field weight in display mode is not respected on custom entity
2 votes

After debugging the Drupal\Core\Field\FormaterBase on how the fields getting rendered, it seems the weights are getting applied to each field in Drupal\Core\Entity\EntityViewBuidler, but they are not ...

View answer
How to update a field on menu_link_content (added using menu_item_extras module) entity from node form
2 votes

There are couple of problems here: The node form has the menu fields hardcoded. See menu_ui_form_node_form_alter() and menu_ui_form_node_form_submit() for more details. Turns out the root cause of ...

View answer
Keep something in cache even after flushing the cache from the Drupal back-end (not drush)
Accepted answer
2 votes

For this use case, you might need to consider another storage instead of cache. warmer -> cache warmer -> storage -> cache storage could be either key value or entity or any other storage you ...

View answer
How to bulk delete Orders in Drupal Commerce module
2 votes

Commerce Order Cleanup is another attempt on this front: Allows to cleanup the orders by various order properties like last changed, status.

View answer
Drupal 7 special chars not working in db_select
2 votes

It doesn't look like anything wrong with query. I'm using drupal 7 with basic setup and one node(nid=3) has 24/7 in title & body and one node(nid=4) has only in body. // Make sure to decode, if ...

View answer
How do I add classes to main menu ul and li?
2 votes

The way to get the main menu with items in all levels has been resolved in Drupal 8 - "Implement menu links as plugins", trying to build a menu tree To add class to ul and li, we got 3 ...

View answer
How to make strings from templates translatable on all pages they appear?
2 votes

Ok, Spent some more time with Localization client & entity translation module to reproduce the same scenario. Since this answer is totally differnt from my previous one, adding as separate comment:...

View answer
Hook_menu to Form with %node wildcard
Accepted answer
2 votes

One of the option is: create a entity reference field in 'school' content type to reference associated contact form. write a helper module that adds a menu item node/%node/contact. Make sure ...

View answer
create url with destination parameter and additional query string to views page with exposed filters
Accepted answer
2 votes

Instead of Trying to generate destination manually, can use drupal_get_destination(). So your above code would be like this: $url = url('admin/dashboard/applications/create/' . $row->nid, array('...

View answer
Caching issue with class extension of RulesDataUI
2 votes

It would be the problem that modulename.rules.inc invoked (or included) just to get all rules hooks. Worth trying to add the class definition in separate file (e.g. includes/rules_ui.inc) and include ...

View answer
How to display a node edit form in custom URL
1 votes

Create a new menu item in a custom module # mymodule.routing.yml mymodule.banner_settings_form: path: /admin/config/system/banner-settings/{node} defaults: _entity_form: node.edit # Copy ...

View answer
Circular dependency on base fields' module
1 votes

Since the dependency is purely on the reference field, we could add the target_type later. For example, setting the target_type at the bundleFieldDefinition wouldn't throw the install's error and set ...

View answer
How can I create an entity reference field to list a subset of roles?
1 votes

Two parts to check here. Is it possible to reference user role (a config entity) Is there a way to restrict the available roles in the field level. reg #1, yes! the out-of-box Drupal core allows ...

View answer
How do I create content during site installation?
1 votes

There are few ways in Drupal 8 to manage site default content: Default content module allows to export/import content via drush and store the content in the structure similar to config in Drupal core....

View answer
How to copy/clone menu of a node when clone with Entity Clone module?
1 votes

Issue #2839833 has a proposal to add entity clone plugin to node entity to handle this special case. Alternatively, we could use the event. Luckily Entity Clone module dispatches an event before &...

View answer
How to allow HTML attribute with namespace using filter
1 votes

One way to solve this problem is to have a custom filter which processes the linkname and convert to sc:linkname. <?php namespace Drupal\my_module\Plugin\Filter; use Drupal\Component\Utility\...

View answer
Hide a list of blocks from Panelizer in-place editor (IPE)
1 votes

One of the options is to extend the IPE controller to remove the unwanted blocks from display. Here are the code changes: Route subscriber: mymodule.route_subscriber: class: Drupal\mymodule\...

View answer
How to use term edit page instead of view page?
1 votes

There are a few ways we could achieve this: Option 1: Introduce a route subscriber in a custom module with below code: $route = $collection->get('entity.taxonomy_term.edit_form'); $...

View answer
How to override prepareTranslation method in Drupal\content_translation\Controller in drupal 8?
1 votes

You can use hook_entity_prepare_form() to override the values from prepareTranslation() on $form_state.

View answer
How to make strings from templates translatable on all pages they appear?
1 votes

Your approach to add the translation string on template or module file level may work for interface translation UI, but not Localization client. Obviously when you have Russian version of the product ...

View answer
Views Data Export print feed icon in template file
0 votes

Another alternative (if you can't override the views-view.html.twig) would be to use a preprocess function: // mysite.module /** * Implements hook_preprocess_views_view(). */ function ...

View answer
Using a custom field as a sub-field in another custom field
0 votes

Basically, the question is how to use a custom field in another field as a property. In an entity a custom field is added by using BaseFieldDefinition::create(). However a property of a field type is ...

View answer
How can I restrict access to a static HTML page served from a subfolder of my site to authenticated users only?
0 votes

One of the options to achieve this is using drupal's private file system. Drupal core out-of-box provides a way to access private files in a secured URL. Here are the steps: upload the directory (e.g....

View answer