This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // The drupal_set_message() function is being deprecated! | |
| // @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x | |
| // > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. | |
| // > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. | |
| // In some custom code. | |
| \Drupal::messenger()->addMessage('Say something else'); | |
| // When trying to print out a simple var. | |
| \Drupal::messenger()->addMessage(print_r($stuff, TRUE)); | |
| // In a Drupal 8 Form's submitForm() handler: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://www.a2hosting.in/kb/installable-applications/optimization-and-configuration/drupal2/installing-drupal-console | |
| Console Install | |
| composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader | |
| Path | |
| echo 'alias drupal="/var/www/html/<project_name>/vendor/bin/drupal"' >> ~/.bashrc | |
| source ~/.bashrc | |
| Command: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wget https://github.com/drush-ops/drush/releases/download/8.1.17/drush.phar | |
| chmod +x drush.phar | |
| sudo mv drush.phar /usr/local/bin/drush | |
| drush --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Implements hook_views_pre_render(). | |
| */ | |
| function custom_views_pre_render(ViewExecutable $view) { | |
| if (isset($view) && ($view->storage->id() == 'super_awesome_view')) { | |
| $view->element['#attached']['library'][] = 'custom/custom_view'; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Example URL - http://xandeadx.ru/blog/drupal/946 | |
| --- | |
| $ composer require drush/drush | |
| --- | |
| $link = \Drupal\Core\Link::createFromRoute('My link', 'entity.node.canonical', ['node' => 123]); | |
| // По пути |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get current user in drupal 8 | |
| Description: In drupal 7 we get the current user object by defining global $user but in drupal 8 this quite different. If you want to get current user object then follow below code. | |
| $current_user = \Drupal::currentUser(); | |
| $uid = $current_user->id(); | |
| It returns user id of current user. | |
| $user_mail = $current_user->getEmail(); | |
| It returns user email id. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Drupal\node\Entity\Node | |
| Working with nodes Load a node by NID: | |
| $nid = 123; // example value | |
| Method 1 | |
| $node_storage = \Drupal::entityTypeManager()->getStorage('node'); | |
| $node = $node_storage->load($nid); | |
| Method 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://www.drupal.org/docs/8/modules/commerce-iats/how-to-setup-recurring-payments | |
| Commerce Membership- | |
| Install Module:- | |
| 1. Drupal commerce install via composer - composer require "drupal/commerce" | |
| 2. Install commerce_recurring module - composer require "drupal/commerce_recurring" | |
| 3. Install commerce_license module - composer require "drupal/commerce_license" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ol> | |
| <li> | |
| <a class="use-ajax" | |
| data-dialog-options="{"width":400}" | |
| data-dialog-type="modal" | |
| href="/node/1"> | |
| First article displayed in modal dialog. | |
| </a> | |
| </li> | |
| <li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function hook_views_pre_render(&$view) { | |
| switch ($view->name) { | |
| case 'YOUR_VIEW_NAME': | |
| // override the global custom text field value | |
| $view->field['nothing']->options['alter']['text'] = 'My custom text'; | |
| $view->field['nothing']->options['alter']['alter_text'] = TRUE; | |
| break; | |
| } | |
| } |