This file contains 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
{# This will work for paragraphs or nodes. #} | |
element['#object'] |
This file contains 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\views\ViewExecutable; | |
use Drupal\views\Views; | |
/** | |
* Implements hook_preprocess_HOOK(). | |
*/ | |
function YOUR_MODULE_NAME_preprocess_HOOK(&$variables) { | |
$some_entity_id = 10; | |
$view = Views::getView('name_of_view'); | |
if (is_object($view) && $most_linked_profiles_view instanceof ViewExecutable) { |
This file contains 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
/** | |
* Delete multiple nodes by ID. | |
*/ | |
function YOU_MODULE_NAME_update_8001() { | |
$nids = [8418,8419]; | |
/** @var \Drupal\node\NodeStorageInterface $storage */ | |
$node_storage = \Drupal::entityTypeManager()->getStorage('node'); | |
if ($nodes = $storage->loadMultiple($nids)) { | |
$node_storage->delete($nodes); |
This file contains 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\Core\Database\Database; | |
/** | |
* Update tags url alias'. | |
*/ | |
function YOUR_MODULE_NAME_update_8001() { | |
// "path_alias" is the name of the table being updated (this comes from the pathauto module) | |
// "alias" is the name of the field/column being updated. | |
// So whats happening here is that, we're updating the alias field/column on the path_alias table. | |
// The update being done is we're replacing the value of "//tags" with "/news-and-events/topics/". |
This file contains 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 YOUR_THEME_some_preprocess_function(&$variables) { | |
$actual_value = array( | |
'my_text' => 'What ever data you wanna pass from php to js', | |
); | |
// Note, for this function to work $actual_value must have a key (my_text) and a value (what ever data...) | |
// the key will be used in javascript to get the value | |
drupal_add_js(array('nameUsedInJs' => $actual_value), 'setting'); | |
} |
This file contains 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 card($, Drupal) { | |
Drupal.behaviors.theme_card = { | |
attach(context) { | |
$('[data-card]', context) | |
.once('theme-card') | |
.each(function eachCard() { | |
// https://inclusive-components.design/cards/ | |
const $link = $(this) | |
.find('a') |
This file contains 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
uasort($valid_variants_ids, function ($a, $b) { | |
// if the first item and the second item have the same value, do nothing. | |
if ($a['study_option_weight'] == $b['study_option_weight']) { | |
return 0; | |
} | |
// if the first item is less than the second item, move the first option down by one, otherwise move it up by one. | |
return $a['study_option_weight'] < $b['study_option_weight'] ? -1 : 1; | |
}); |
This file contains 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
settings: | |
allowed_values: { } | |
# Add the line below to your file as it will reference the function you'll create in your .module file | |
allowed_values_function: example_allowed_values_function |
This file contains 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
/** | |
* @file | |
* Install, update and uninstall functions for the YOUR_MODULE_NAME module. | |
*/ | |
/** | |
* Implements hook_update_N(). | |
* | |
* Update field_example on the my_example_setting site | |
* setting to have all the term_example taxonomy terms selected. |
This file contains 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
$route_name = \Drupal::routeMatch()->getRouteName(); | |
if ($route_name == 'entity.node.canonical') { | |
node = \Drupal::routeMatch()->getParameter('node'); | |
$node_type = $node->getType(); | |
$title = $node->getTitle(); | |
$visible = $node->isPublished(); | |
$node->setPromoted(TRUE); | |
$uid = $node->getOwnerId(); | |
// $author will be user object of the person who created the node. |
NewerOlder