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
<?php | |
use \Drupal\Core\Url; | |
$current_url = Url::fromRoute('<current>'); | |
$path = $current_url->getInternalPath(); | |
// Retrieve an array which contains the path pieces. | |
$path_args = explode('/', $path); | |
$nid = $path_args['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
$entity_st = \Drupal::entityManager()->getStorage('entity_name'); | |
$entity_obj = $entity_st->load(entity_id); | |
$field_value = $entity_obj->get('field_name')->value; |
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
<?php | |
// Get all values of field reference as array | |
// $entity is entity object - node, user, taxonomy | |
$field_arr_ref = $entity->field_name_reference->getValue(); | |
$field_arr_id = $field_arr_ref[0]['target_id']; | |
//Another method to get all values | |
$ref_entities = $entity->get('field_name')->referencedEntities(); | |
// Get only one value |
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 hook_views_query_alter(\Drupal\views\ViewExecutable $view, \Drupal\views\Plugin\views\query\QueryPluginBase $query) { | |
if ($view->id() == 'view_name' && $view->current_display == 'block_1') { | |
$current_url = Url::fromRoute('<current>'); | |
$path = $current_url->getInternalPath(); | |
// Retrieve an array which contains the path pieces. | |
$path_args = explode('/', $path); | |
$node_id = $path_args['1']; | |
$node_object = Node::load((int) $node_id); | |
$tag_arr = $node_object->field_tags->getValue(); | |
foreach ($tag_arr as $key => $value) { |
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
$node->field_image->entity->url(); |
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
$url_object->toString(); |
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\image\Entity\ImageStyle; | |
$image_url = ImageStyle::load('customer_logo_150x120_')->buildUrl($node->field_customer_logo->entity->getFileUri()); |
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
First we have to get the list of blocks with block id which we can we get if we execute this query | |
<?php | |
$ids = \Drupal::entityQuery('block')->execute(); | |
?> | |
If the block we created is not in this list(in the case of creation of custom block not assigned to any regiom) | |
, we have to place the block in some region and disable it. | |
<?php | |
$block = \Drupal\block\Entity\Block::load($block_id); |
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
content.field_link.0['#url'] |
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 Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |