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\file\Entity\File; | |
use Drupal\image\Entity\ImageStyle; | |
// File ID. | |
$fid = 123; | |
// Load file. | |
$file = File::load($fid); | |
// Get origin image URI. | |
$image_uri = $file->getFileUri(); | |
// Load image style "thumbnail". |
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 | |
// Allow other modules to alter your data. | |
$data = [ | |
'#type' => 'markup', | |
'#markup' => t('This is the default text.'), | |
]; | |
\Drupal::moduleHandler()->alter('MODULE_some_action', $data); | |
/** | |
* Implements hook_MODULE_some_action_alter(). |
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 | |
// Some entity alias (node, taxonomy_term, user, etc). | |
$alias = '/about'; | |
// Get URL obj. | |
$url = Url::fromUri('internal:' . $alias); | |
// Check exist alias. | |
if ($url->isRouted()) { | |
$params = $url->getRouteParameters(); | |
$entity_type = key($params); | |
// GEt entity. |
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 | |
// Load term by name | |
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => 'some_name']); |
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 | |
/** | |
* Implements hook_preprocess_views_view_field(). | |
*/ | |
function MODULE_preprocess_views_view_field(&$variables) { | |
/** @var \Drupal\views\ViewExecutable $view */ | |
$view = $variables['view']; | |
if ($view->id() == 'schedule') { | |
if ($view->current_display == 'embed_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
if (class_exists('Memcached', FALSE)) { | |
$class_loader->addPsr4('Drupal\\memcache\\', 'modules/contrib/memcache/src'); | |
$settings['bootstrap_container_definition'] = [ | |
'parameters' => [], | |
'services' => [ | |
'settings' => [ | |
'class' => 'Drupal\Core\Site\Settings', | |
'factory' => 'Drupal\Core\Site\Settings::getInstance', | |
], |
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
$values = FieldConfig::loadByName('node', 'BUNDLE', 'FIELD')->getSetting('allowed_values'); |
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 | |
namespace Drupal\my_module\Form; | |
use Drupal\Core\Form\FormBase; | |
use Drupal\Core\Form\FormStateInterface; | |
/** | |
* Class TestAjaxFormSelect. | |
*/ |
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 | |
/** | |
* @file | |
* Contains \Drupal\hello_world\Form\AddAnotherItem. | |
*/ | |
namespace Drupal\hello_world\Form; | |
use Drupal\Core\Form\FormBase; | |
use Drupal\Core\Form\FormStateInterface; |
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\Menu\MenuLinkTreeInterface; | |
use Drupal\Core\Menu\MenuTreeParameters; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* The menu link tree service. | |
* | |
* @var \Drupal\Core\Menu\MenuLinkTree |
NewerOlder