// Load file object
$file = File::load($fid);
// Get uri (public://foo/bar/baz.png)
$uri = $file->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
drush eval '\Drupal::service("update.update_hook_registry")->setInstalledVersion("mOdule_name", "previous_update_number");' |
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
Steps to add a new operation to Entity: | |
- In the entity class: | |
-- Add definition in handlers/form | |
-- Override handlers/route_provider with a new route generator. | |
-- Add route template in links | |
- Create a new form to manage the operation. | |
- Generate a new route in the route generator class. | |
- Add operation in the entity's ListBuilder. |
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
#!/bin/bash | |
# | |
# 2024-02-05 - Creado con gpt-4-1106-preview | |
# Por Pedro Pelaez | |
# | |
# Define una función para imprimir mensajes en azul | |
print_blue() { | |
echo -e "\033[34m$1\033[0m" |
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
#!/bin/bash | |
# Fix code style automatically. | |
# | |
# To create the command 'ddev phpcbf', create in '.ddev/commands/web' a new file 'phpcbf'. | |
# This require, in project, install 'squizlabs/php_codesniffer' and 'drupal/coder' how a dev dependency. | |
# 2023 By Pedro Pelaez <[email protected]> | |
folders="" |
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
/** | |
* Localhost setup. | |
*/ | |
$databases['default']['default'] = [ | |
'database' => 'db', | |
'username' => 'db', | |
'password' => 'db', | |
'prefix' => '', | |
'host' => 'mariadb', | |
'port' => '3306', |
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
// Get administrators. | |
$roles = user_role_names(FALSE, 'administer reservable_list_form petitions'); | |
$rids = array_keys($roles); | |
$uids = Drupal::service('entity_type.manager')->getStorage('user')->getQuery() | |
->condition('roles', $rids, 'IN') | |
->execute(); | |
$users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($uids); |
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
Drupal\Core\PageCache\ResponsePolicy\KillSwitch | |
class ... | |
/** | |
* Kill cache service. | |
* | |
* @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch | |
*/ | |
protected $killSwitch; |
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
public static function getFieldConfig($nodeBundle, $field_name) { | |
$entity_field_manager = \Drupal::service('entity_field.manager'); | |
$entity_field_manager->useCaches(FALSE); | |
$fieldsSettings = $entity_field_manager->getFieldDefinitions('node', $nodeBundle); | |
if (!isset($fieldsSettings[$field_name])) { | |
return NULL; | |
} | |
/** @var \Drupal\field\Entity\FieldConfig $fieldSetting */ | |
$fieldSetting = $fieldsSettings[$field_name]; | |
return $fieldSetting; |
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
// Load twig engine in cron. | |
include_once \Drupal::root() . '/core/themes/engines/twig/twig.engine'; | |
// Render a render array. | |
$renderer = \Drupal::service('renderer'); | |
$result = $renderer->renderPlain($output); |
NewerOlder