0% found this document useful (0 votes)
19 views

Drupal Syntax List

Uploaded by

prem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Drupal Syntax List

Uploaded by

prem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Entity Syntax Description Example Site URL

Node {{ node.field_name.0}} or {{ node.field_name.value}} 0 is also used to render value http://spinx.local/projects/lightbay_capital/web/foundation


Title {{ label }} Label is used to render the title http://spinx.local/projects/lightbay_capital/web/foundation
{{ node.label }} node is used to render node label http://kkg.test/node/1
Text {{ node.field_name.value }} Using value we can render any text data which is basic html type http://spinx.local/projects/lightbay_capital/web/foundation
Text (Formatted) {{ node.field_name.value|raw }} Raw filter is used to render formatted data from full html field http://spinx.local/projects/lightbay_capital/web/foundation
Body {{ node.body.value|raw }} or {{ node.body.0.value}} "body" is used to render data from body field http://spinx.local/projects/lightbay_capital/web/foundation
Link {{ node.field_name.value }} Link is called similar to text fields http://spinx.local/projects/lightbay_capital/web/foundation
Link-URL {{ node.field_name.uri }} uri is used to call the link url -
Link-Text {{ node.field_name.title }} title is used to call the link text -
Image {{ file_url(content.field_name['#items'].entity.uri.value) }} "['#items']" or 0 is used to render single image in node from image field http://spinx.local/projects/lightbay_capital/web/foundation
{{ content.field_name.0 }} or {{ file_url(node.field_counter_banner_ah.entity.
Media field_media_image.entity.fileuri) }} 0 is used to render image and in this case image is rendered as URL http://kkg.test/node/1

Field Collection {% for details in node.field_collection_name %} {% endfor %} For loop is used to render field collection items http://spinx.local/projects/lightbay_capital/web/foundation
Image {{ file_url(details.getFieldCollectionItem().field_name.entity.fileuri) }} "details" is the name of variable used in for loop and image is url format http://spinx.local/projects/lightbay_capital/web/foundation
Media Image {{ details.getFieldCollectionItem().field_name|file_url }} "file_url" is used as filter for rendering url of media image http://spinx.local/projects/lightbay_capital/web/foundation
Text {{ details.getFieldCollectionItem().field_name.value }} "details" is the name of variable used in for loop http://spinx.local/projects/lightbay_capital/web/foundation

Block {{ content.field_name.0 }} or {{ content.field_name.value }} 0 is also used to render value http://spinx.local/projects/lightbay_capital/web/


Title {{ label }} Label is used to render the title http://spinx.local/projects/lightbay_capital/web/
Text {{ content.field_name.value }} Using value we can render any text data which is basic html type http://spinx.local/projects/lightbay_capital/web/
Body {{ content.body.0|raw }} 0 is used to render value of body field http://spinx.local/projects/lightbay_capital/web/
Link {{ content.field_name.value }} Link is called similar to text fields http://spinx.local/projects/lightbay_capital/web/
Image {{ content.field_name.0|render|trim|striptags }} Render, trim and striptags is used to format and render image url http://spinx.local/projects/lightbay_capital/web/
Media {{ content.field_name.0|render|trim|striptags }} Render, trim and striptags is used to format and render image url http://spinx.local/projects/lightbay_capital/web/
Loop {% for key, item in content.field_name if key|first != '#' %} {{ item}} {% endfor %} For repeatative items use key loop for getting seperate id http://spinx.local/projects/lightbay_capital/web/

View {{ fields.field_name.content }} Content is used to render data http://spinx.local/projects/lightbay_capital/web/news-listing


Link to content {{ fields.view_node.content|striptags }} View node is used to call link to content and striptags is used to remove tags http://spinx.local/projects/lightbay_capital/web/news-listing
Title {{ fields.title.content }} Title is used to call content title in view http://spinx.local/projects/lightbay_capital/web/news-listing
Authored date {{ fields.created.content }} Created is used to call date of post authored day http://spinx.local/projects/lightbay_capital/web/news-listing
Text {{ fields.field_name.content }} Field name is the name of field http://spinx.local/projects/lightbay_capital/web/news-listing
Link {{ fields.field_name.content|striptags }} Striptags is used to remove tags from link http://spinx.local/projects/lightbay_capital/web/news-listing
Image {{ fields.field_name.content|render|trim|striptags }} Render, trim and striptags is used to format and render image url http://spinx.local/projects/lightbay_capital/web/news-listing
Media {{ fields.field_name.content|render|trim|striptags }} Render, trim and striptags is used to format and render image url http://spinx.local/projects/lightbay_capital/web/news-listing

Paragraph {{ content.field_name }} Content is used to render data -


Text {{ content.field_name }} Content is used to render data -
Text (Formatted Long) {{ content.field_name }} Content is used to render data -

Insert Current Year in footer {{ 'now'|date('Y') }} Y prints year like 2019 -


Region {{ drupal_region('machine_name_of_region') }} It is called using Twig Tweak Module http://spinx.local/projects/lightbay_capital/web/news-listing
Block {{ drupal_block('machine_name_of_block') }} It is called using Twig Tweak Module http://spinx.local/projects/lightbay_capital/web/news-listing
View (Block Type) {{ drupal_view('machine_name_of_view','block_1') }} It is called using Twig Tweak Module http://spinx.local/projects/lightbay_capital/web/news-listing
View (Page Type) {{ drupal_view('machine_name_of_view','page_1') }} It is called using Twig Tweak Module http://spinx.local/projects/lightbay_capital/web/news-listing

Module Name Installation URL Working


Simple Login composer require 'drupal/simplelogin:^3.3' Allow users to attach their own background images/ own background color to user login, password, registration pages.
Admin Toolbar composer require 'drupal/admin_toolbar:^2.0' Improve the default toolbar to transform it into a drop-down menu, providing a fast access to all administration pages.
Path Auto composer require 'drupal/pathauto:^1.5' Generates URL/path aliases for various kinds of content without requiring the user to manually specify the path alias.
View Bulk Operation composer require 'drupal/views_bulk_operations:^3.3' It shows a checkbox in front of each node, and adding a select box containing operations that can be applied.
Media Default module of Drupal, need to Install from Extend tab Allows Media Library facility for user to add existing media items.
Entity Construction Kit composer require 'drupal/eck:^1.0' Allows the creation and management of entity types with custom properties; adding bundles to entity types; and fields to bundles.
Paragraph composer require 'drupal/paragraphs:^1.10' It allows to make things cleaner so that you can give more editing power to your end-users.
Webform composer require 'drupal/webform:^5.5' Webform is the module for making forms and surveys in Drupal. After a submission customizable e-mails can be sent to administrators and/or submitters.
Display Suite composer require 'drupal/ds:^3.4' Display Suite allows you to take full control over how your content is displayed using a drag and drop interface.
Field Collection composer require 'drupal/field_collection:^1.1' A field collection is internally represented as an entity, which is embedded in the host entity.
Redirect After Login composer require 'drupal/redirect_after_login:^2.5' A simple module providing a feature to redirect users according to an URL-defined parameter after logging in. Allows redirect only internal url of site.
Twig Tweak composer require 'drupal/twig_tweak:^2.4' It provides a Twig extension with some useful functions and filters that can improve development experience.
Inline Entity Form composer require 'drupal/inline_entity_form:^1.9' Provides a widget for inline management (creation, modification, removal) of referenced entities. Existing entities can also be referenced.
Simple Mega Menu composer require 'drupal/simple_megamenu:^1.0' This module provides a new content entity type, Simple MegaMenu. These entities can be managed as the node entity type for creating mega menu.
Block Class composer require 'drupal/block_class:^1.0' Block Class allows users to add classes to any block through the block's configuration interface.
Captcha composer require 'drupal/captcha:^1.0' A CAPTCHA is a challenge-response test most often placed within web forms to determine whether the user is human.
ReCaptcha composer require 'drupal/recaptcha:^2.4' Uses the Google reCAPTCHA web service to improve the CAPTCHA system. It is tough on bots and easy on humans.
Entity Browser composer require 'drupal/entity_browser:^2.2' This module provides a generic entity browser/picker/selector. It can be used in any context where one needs to select few entities and do something with them.
Sitemap composer require 'drupal/sitemap:^1.5' This module provides a site map that gives visitors an overview of your site. It can also display the RSS feeds for all blogs and categories.
SMTP Authentication Support composer require 'drupal/smtp:^1.0' This module allows Drupal to bypass the PHP mail() function and send email directly to an SMTP server. The module supports SMTP authentication and can even connect to servers using SSL if supported b
FormDazzle composer require 'drupal/formdazzle:^2.1' This modules provides suggestion for form twigs and input twigs with form id without using hooks
Views Merge Rows composer require 'drupal/views_merge_rows:^2.1' After installing the module, enable it in Advanced Views settings. You then get the “Merge rows” item in the OTHER section of the Views UI
Views Filters Populate composer require 'drupal/views_filters_populate:^1.1' This module "populates" other filters on the view with the provided value, allowing to use one exposed filter to search several others.
Views Exposed Form Fieldset composer require 'drupal/views_ef_fieldset:^1.5' This module provides options to render exposed filters and exposed sorts fields in fieldsets.
Webform Content Creator composer require 'drupal/webform_content_creator:^1.7' Creates node for webform entries

Call JS on particular page /** Used in Phatmojo project homepage


* Implements hook_page_attachments_alter().
*/
function phatmojo_page_attachments_alter(&$attachments) {
if (\Drupal::service('path.matcher')->isFrontPage()) {
$attachments['#attached']['library'][] = 'phatmojo/home-script';
}
}

Menu Active Class JS /** Menu active class **/ Add .navbar-menu class in ul
$(".navbar-menu li a").each(function () {
if (this.href == window.location.href) {
var t = $(this);
$(this).addClass("active");
}

Vagrant Issues Solution


The machine index which stores all In this case go to c:/users/user_name/vagrant.d/data/machine-index and move both index and
required information about index.lock file and save it at other location as backup and then do vagrant up. It works fine. The
running Vagrant environments has data is also saved and all sites works fine without data loss.
become corrupt. This is usually
caused by external tampering of the
Vagrant data folder.

The version of powershell currently In this case first check your powershell version. Go to start menu type "powershell" then a
installed on this host is less than command prompt like blue color window will open, in that reach the root i.e "c:/", type
the required minimum version. Please "$PSVersionTable", after this command a version table will come as output, now check for line
upgrade the installed version of "PSVersion", if it is less than 3.x then open command prompt and execute command "choco
powershell to the minimum required upgrade powershell" -> requirement is you must have "Chocolaty" installed in your system.
version and run the command again.

Installed version: N/A


Minimum required version: 3

Vagrant failed to initialize at a very early Try command "Vagrant reload"


stage
"Temporary file 'temporary://filec1SctN' Create a folder named "tmp" in Sites/default/files, then check the path in Admin->
could not be created" OR Configuration-> File Systems, after that give permission in git bash, go to project folder then
"Drupal\Core\File\Exception\FileWriteExc execute the command "sudo chmod 777 -R sites/default/files" and check for this line in
eption: Temporary file 'temporary: settings.php "# $config['system.file']['path']['temporary'] = '/tmp';"
//fileWuJBYN' could not be created. in
Drupal\Core\File\FileSystem-
>saveData()" OR "The specified file
'temporary://fileZ5iuVy' could not be
copied because the destination directory
is not properly configured. This may be
caused by a problem with file or directory
permissions."
PHP Warning: 'vcruntime140.dll' 14.0 is When we install any module, if this error arrives, check whether "composer info" command is
not compatible with this PHP build linked working or not, if not working then make sure you have Microsoft Visual Studio C++ is
with 14.16 in Unknown on line 0 downloaded in your system, if not then go to this link (https://visualstudio.microsoft.
com/downloads/#microsoft-visual-c-redistributable-for-visual-studio-2019), download and install
the software, then this problem will be solved.

Import DB through command


1. Place the file db.sql in the same folder where you have the Project (Inside project folder, where web is allocated)
2. Create a empty database "mydb" in your server
3. vagrant ssh as you normally do to get into the VM
4. run the following command to import the db
5. $ mysql -u root -p mydb < db.sql
Field label Field syntax Description Example site URL

{{ row.content['#view'].style_plugin.render_tokens[ loop.index0 ]['{{


Render field in Unformatted View Twig File YOUR_FIELD_NAME }}'] }} The syntax must be within a for loop to render a particular
{{ row.content['#view'].style_plugin.render_tokens[
field loop.index0 ]['{{ field_portfolio_category }}'] }}

To enable File Field in Webform Module In settings.php do this: $settings['file_private_path'] = 'sites/default/files/private'; and clear all caches ; )
Field label Field syntax Description Example site URL
Field label Field syntax Description Example site URL
Field label Field syntax Description Example site URL
Description Code Example site URL
Overide drupal core library https://drupal.stackexchange.com/questions/267853/how-do-i-use-an-older-jquery-version
https://drupal.stackexchange.com/questions/248131/how-do-i-use-a-jquery-version-different-from-the-default-one-used-by-core
$view = Views::getView( 'product_category_listing' );
$view->setDisplay( 'all_product_category_landing' );
$view->execute();
Drupal twiq twig list of result code $variables['all_product_category_landing_count'] = count( array_keys( $view->result ) );
Content Import https://www.drupal.org/project/contentimport
https://www.drupal.org/project/csv_importer
https://www.drupal.org/project/imce
https://drudesk.com/
Save term pogramatically https://befused.com/node/315
https://www.valuebound.com/resources/blog/how-to-create-a-drupal-entity-programmatically-drupal-8
https://gist.github.com/himerus/f6875db8d3b6c575074c10fb4fb0df95
https://drupal.stackexchange.com/questions/108868/programmatically-create-a-term
Add term in to node by field using term id https://drupal.stackexchange.com/questions/197610/8-how-to-programmatically-add-terms-to-an-existing-node
Add parent term to child term http://purencool.com/accessing-taxonomys-name-and-parent-tid-in-drupal-8
Load term by name https://drupal.stackexchange.com/questions/225209/load-term-by-name
Simple node importer Module https://www.drupal.org/project/simple_node_importer
Total Control Admin Dashboard Module https://www.drupal.org/project/total_control
https://www.drupal8.ovh/en/tutoriels/55/create-taxonomy-term-programmatically-on-drupal-8
https://www.zyxware.com/articles/5555/drupal-how-can-we-load-node-file-taxonomy-entities-by-id-in-drupal-8
https://drupal.stackexchange.com/questions/233522/how-to-get-term-name-from-a-tid
File save code http://web-tricks.org/content/how-to-attach-an-image-or-file-to-node-in-drupal-8-programmatically

Create paragraph entity https://www.drupal.org/project/paragraphs/issues/2684389


https://drupal.stackexchange.com/questions/236544/programmatically-append-multiple-paragraphs-to-entity-reference-field-on-node
https://drupalium.com/articles/get-add-update-paragraphs-fields-from-config-pages-entity-programmatically
https://drupal.stackexchange.com/questions/243047/how-to-add-term-programmatically-in-paragraph-field
https://drupal.stackexchange.com/questions/243047/how-to-add-term-programmatically-in-paragraph-field
https://drupal.stackexchange.com/questions/213379/programmatically-update-an-entity-reference-field
https://drupal.stackexchange.com/questions/194909/how-to-store-values-to-field-collection-or-paragraphs-programmatically
Field label Field syntax Description Example site URL

You might also like