Frequently Asked Questions In Drupal

Frequently Asked Questions in Drupal

Q: Using a View’s exposed Sort Criteria. when (on the front end) I hit the Sort Criteria’s “Apply” button I get redirected to the home page.

A: I think you are using panel. So use content panes only, not block views, etc. and make sure in views UI in middle column to set “use panel path” to yes.

 

Q: I have an Entity, It installs correctly and works the way that I want it to. But getting one issue i.e. I want to attach an entity reference to a specific vocabulary. But when I go to install it, I get the following error: Drupal\Component\Plugin\Exception\PluginNotFoundException: The “custom_vocabulary” entity type does not exist. in /brew/www/html/core/lib/Drupal/Core/Entity/EntityTypeManager.php:133

A: Vocabularies are bundles of the entity type taxonomy term. If you want to reference a vocabulary then you need to set the taxonomy_term first as target type and second restrict the field to a specific vocabulary as target bundle.

 

Q:  How to Render custom html below a custom form ?

A: You have to use the power of render arrays.

 

Q: How to show event calendar and show active dates on which event is.

A: It can be done with calendar module. Go to month view, add a block view and build your underneath view, then add this block view as a footer (middle column in views ui) in your month view (Global: View area), then pass arguments in settings to be the same as your month view.

 

Q: Javascript & Ajax failed to load on many pages like field editing & views editing pages.

A: Jquery Update module is very helpful but new jquery versions can cause issues with other dependent modules. The module is important not only to keep your site up to date but also allow for theme-specific control to ensure compatibility.

 

Q: Errors found Entity/field definitions

A: Sometimes in custom or contrib module updates, the schema for entities can become incorrect or have problems If you have drush, running drush entity-updates should fix this.

 

Q: How to detect 404 in THEME file. For the same I want to attach a library to a custom 404 page. How can I know if the current response will be a 404 Page Not Found?

A: In your hook within your theme file:

$status = \Drupal::requestStack()->getCurrentRequest()->attributes->get(‘exception’);

if ($status && $status->getStatusCode() == 404) {

$page[‘#attached’][‘library’][] = ‘themename/notfound’;

}

 

Q: How do I restrict a user from edit his/her own profile?

A: You have 2 options, 1st is hide them from the form on the Manage Form tab, or use a form alter hook to set #access to FALSE if they don’t fit a certain role. You can also try the Field Permissions module.

 

Q: How to show a list of students: pairing entity references?

A: You can use Entity Views Attachment, this can help you.

 

Q: How to set a flag at node when user view node? I have a content type ‘page’. When a user views this node, I want a flag to be set automatically not by flag module link.

A: You set this using hook_node_view like this

function custom_node_view($node, $view_mode, $langcode) {

global $user;

if($node->type == ‘page’ && $view_mode == ‘full’)

{

$flag = flag_get_flag(‘node_view’);

if (!$flag->is_flagged($node->nid)){

$flag->flag(‘flag’, $node->nid, user_load($user->uid), TRUE);

}

}

}

 

Q: How do I set drush default uri so that I dont need to type drush uli –uri http://localhost/… everytime i want an one time login?

A: You need to create a drush folder but this is optional, And Create/Update drushrc.php inside your drush folder with the following option:

<?

$options[‘uri’] = ‘http://sitename.com’;

 

Q: How can I add extra info like lang=”ar” dir=”rtl” to the <html> tag like the following?

<html{{ html_attributes }} lang=”ar” dir=”rtl”>

 

A: ou can use the following code, even though for those specific values, I would find a different way (e.g. setting the language for the shown page).

{% html_attributes.setAttribute(“lang”, “ar”) %}

{% html_attributes.setAttribute(“dir”, “rtl”) %}

<html{{ html_attributes }}>

 

Inside hook_preprocess_html(), since $variables[‘html_attributes’] is an Attribute object, so you can use Attribute::setAttribute().

 

$variables[‘html_attributes’]->setAttribute(“lang”, “ar”);

$variables[‘html_attributes’]->setAttribute(“dir”, “rtl”);

 

Q: How to lazy load on a Views?

A: Below are some modules that you can use are :

  1. Views Infinite Scroll
  2. Views Load More
  3. Image Lazyloader

 

Q: Whats the best way to check if a menu already exists if I already know it’s ID.

A: A menu is a config entity, which means you can use standard entity API to load it.

\Drupal\system\Entity\Menu::load() or \Drupal:entityTypeManager()->getStorage(‘menu’)->load()

 

Q: Missing node_reference warning

A: Node_reference is just a sub-module of the References module; that’s why you can’t download it using Drush. Instead, download the References module.

 

Q: What is a patch in Drupal?

A: A patch is a file that contains a list of differences between one set of files, and another.  Through patches, all the changes in code like additions or deletions to Drupal core can be made. Also, patches can be used to make changes to another copy of the original or main file.

 

Q: How database system of Drupal works?

A: In a database Drupal stores information, and each information has its own database table.  For example, the basic information regarding the nodes of your site are stored and kept in the node table, and if you use the CCK module to add fields to your nodes, the field information is stored in a separate table.

 

Q: What is the use of Ctools in Drupal?

A: This suite is a set of APIs and tools, and it makes easier to handle AJAX requests and tell the client what to do with them.

 

Q: How do I access the Drupal admin panel, when the login block is disabled?

A: We can access the login screen simply through the following URL.

http://sitename.com/?q=user or if the clean URL is enabled  http://sitename.com/user

Similarly if you can’t access the logout link and need to logout, you can do so by using the URL http://sitename.com/?q=logout  alternatively with clean URLs enabled you can try http://sitename.com/logout .

 

Q: How to make my Drupal site offline to public, while it is under construction?

A: You can set your Drupal site in off-line mode, while it is being developed. Just click Administer » Site maintenance.

 

Q: How can I enable clean URLs in Drupal?

A: Navigate to Administer » Site configuration » Clean URLs. By default, it will be disabled. Select enabled and click the save configuration button.

 

Q: How do I get my site to have SEO-friendly URLs?

A: The Pathauto module automatically generates URL/path aliases for various kinds of content without requiring the user to manually specify the path alias.

 

Q: How do I show different Drupal themes on different pages?

A: Yeah it’s possible! You can apply different themes to different pages in your drupal site simply with the help of a cool module called ‘Sections’.

 

Q: How can I customize my 404 – Page not found page?

A: Create a new page with some extra information. Remember its node ID, Go to Administer > Site configuration > Error reporting, Set Default 404 (not found) page to the node ID you just created, Save your settings.

 

Q: How can I add a new Block In Drupal?

A: Go to Administer » Blocks and click on the Add Block link (tab).

 

Q: How can I create a custom region in my Drupal template?

A: It’s basically a two-step process. 1st define the custom region in your theme’s .info file and 2nd insert some PHP in your theme’s page.tpl.php file wherever you would like the new region to appear.

 

Q: How can I add custom PHP codes in my Drupal blocks?

A: By default, drupal will not allow inserting PHP code directly inside a in a block. You need to activate a drupal module called PHP filter via, Administer » Site building » Modules. Even though this module ships with drupal, it remains disabled by default.

 

Q: What are hooks in Drupal?

A: Hooks are drupal api code which allows module to interact with the Drupal core.

 

Q: What is contextual filter?

A: contextual filters were called arguments in Views and a lot of documentation, tutorials and Views-compatible modules still use that term. If you see the term argument, it should be interpreted either as a contextual filter, or the value provided to a contextual filter.

 

Q: Which files are required for Creating the Drupal Module?

A: MODULENAME.info and MODULENAME.module file are required for creating the module.

 

Q: Which files are required for Creating the Drupal Theme?

A: .info (declares the theme features) and page.tpl.php (defines the layout)

 

Q: How can add the Captcha in registration page for drupal?

A: Use the captcha and recaptcha module.

 

Q: If I want to add the extra fields in registration field then what should we do?

A: Use profile module.

 

Q: List the modules required for building a social networking website in Drupal.

A: Below are the modules that can help you to build a social networking site, which are:

  • Advanced Forum
  • Advanced Profile Kit
  • Application Toolbar (Appbar)
  • Author Pane
  • Buddylist2 Package
  • Buddylist: list your social network
  • CiviCRM: manage community contacts, relationships, and activities
  • CiviNode and CiviNode CCK: Tools For Integrating CiviCRM Contacts Into Drupal Content
  • Comment Notify
  • FOAF: friends of a friend
  • Facebook-style Statuses
  • Family: Record, display, and analyze genealogical data.
  • Flag Friend
  • Friend
  • FriendList
  • Front: Show group membership and events
  • Gigya Socialize Module
  • Invite: send invitations to join your site
  • Notice Feed
  • Organic Group
  • Profile Setup
  • Radioactivity
  • Sports Pickem
  • Tellafriend Node
  • User Invite
  • User Relationships
  • UserTag:Tag