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
{% set node_path = path('entity.node.canonical', { 'node': node.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
_context.elements['#paragraph']._referringItem.fielddefinition.label |
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
// List things with Drush | |
Node Types - drush ev "print_r(array_keys(node_type_get_types()));" | |
User Roles - drush ev "print_r(array_keys(\Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple()));" | |
Fields (on a content type) - drush ev "print_r(array_keys(\Drupal::entityManager()->getFieldDefinitions('node', 'insight')));" | |
Vocabularies - drush ev "print_r(array_keys(taxonomy_vocabulary_get_names()));" | |
Image Styles - drush ev "print_r(array_keys(\Drupal::entityTypeManager()->getStorage('image_style')->loadMultiple()));" | |
// Running db updates for one module | |
drush ev "module_load_install('webform');webform_update_7423();" |
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
// chaining with .entity. | |
$query = \Drupal::entityQuery('node'); | |
$articles_by_name = $query->condition('type', 'article') | |
->condition('uid.entity.name', 'admin') | |
->execute(); | |
//Equal/>=/<=/etc (3rd parameter) | |
// Find particular nodes published in the last year. | |
$query = \Drupal::entityQuery('node'); |
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
// Find all users with the Administrator role. | |
$admin_user_ids = \Drupal::entityQuery('user') | |
->condition('roles', 'Administrator', 'CONTAINS') | |
->execute(); |
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
//prevent 2 or more of the CTA paragraphs from being chosen in a paragraph reference field | |
function mymodule_form_node_form_alter(&$form, FormStateInterface $form_state) { | |
$node = $form_state->getFormObject()->getEntity(); | |
// Add validation to nodes by type | |
if(in_array($node->getType(),['campaign_page','case_study','event','insight','resource'])) { | |
$form['#validate'][] = '_mymodule_node_form_validate'; | |
} | |
} |
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
// CREATE | |
// Procedural Wrapper | |
$node = entity_create('node', array( | |
'title' => 'Make blogs great again', | |
'body' => 'This is where the body content goes. You could load text from a seperate file here too if you didn\'t want to have it all inline and have to worry about things like character escaping.', | |
)); | |
// Static Create method | |
$node = Node::create(array('title' => 'First!')); | |
$node->save(); |
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
// single | |
$service = \Drupal::service('entity_type.manager')->getStorage('node'); | |
$node = $service->load(22); | |
// multiple | |
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple(array(22, 14, 8)); |
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
drupal generate:module | |
drupal generate:entity:content | |
drupal generate:entity:bundle | |
// create a module without having to answer questions | |
drupal generate:module \ | |
--module="modulename" \ | |
--machine-name="modulename" \ | |
--module-path="/modules/custom" \ |
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
$config[‘image.settings’][‘suppress_itok_output’] = TRUE; | |
$config[‘image.settings’][‘allow_insecure_derivatives’] = TRUE; |