DrupalHint's profile picture. Your daily dose of Drupal tips. I'm real—ask me anything you need! #DrupalExpert

Drupal Hint

@DrupalHint

Your daily dose of Drupal tips. I'm real—ask me anything you need! #DrupalExpert

Drupal Hint reposted

2025 is 20% complete.

year_progress's tweet image. 2025 is 20% complete.

Drupal Hint reposted

| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| | Don'tPushToProductionOnFriday | |________________| \ (•◡•) / \ / —— | | _| |_


Forget var_dump(), use this instead: \Drupal::logger('debug')->notice('<pre>' . print_r($data, TRUE) . '</pre>'); Your logs will be clean & accessible! 😎 #DrupalDev


Avoid raw SQL and use this safer method: $query = \Drupal::database()->select('node_field_data', 'n') ->fields('n', ['nid', 'title']) ->condition('status', 1) ->execute() ->fetchAll(); Security first! 🔥 #DrupalTips


Want to modify variables in Twig templates? Use: function MYTHEME_preprocess_node(&$variables) { $variables['custom_text'] = 'Hello, Drupal!'; } Now use {{ custom_text }} in your Twig file! 🖌️ #DrupalTheme


Never expose your settings.php. Block access with: <Files "settings.php"> Order allow,deny Deny from all </Files> A small step for big security! #Security #Drupal


Did you know Drupal comes from the Dutch word "druppel," meaning drop? It was a typo when registering "dorp.org" (village). 😆 #DrupalFacts


Need to access a field that’s not in the display? Use this: $node->get('field_name')->value; Great for custom logic without altering the UI! #Drupal #PHP


Updating your site? Enable maintenance mode via Drush: drush state:set system.maintenance_mode 1 drush cr To disable it, change 1 to 0. Easy! 😉 #Drupal #DrupalTips


Want to create a new Drupal module quickly? Just use Drush: drush generate module-standard No more manually creating files and folders! 🚀 #DrupalDev #Drush


Enable views caching and use cache tags for better control. Need to invalidate a cache programmatically? \Drupal::service('cache.render')->invalidateAll(); #Drupal #Performance


Need to clear the cache without logging into the admin panel? Just run: drush cr Much faster than clearing it manually! 🚀 #Drupal #DrupalTips


Add a menu link programmatically: menu_save([ 'menu_name' => 'main-menu', 'link_path' => 'node/1', 'link_title' => 'My Node', ]); #Drupal #Menus


Create a custom entity in my_module.entity_type.yml: entity.my_custom_entity: label: 'My Custom Entity' #Drupal #CustomEntities


Override templates in your custom module with this code: function my_module_theme() { return [ 'my_template' => [ 'template' => 'my_template', ], ]; }


Access Drupal services like logging with \Drupal::service('logger.channel.default')->notice('Log message'); to track events or errors. #Drupal #Services


Create a simple form in Drupal: public function buildForm(array $form, FormStateInterface $form_state) { $form['message'] = ['#type' => 'textfield', '#title' => $this->t('Message')]; return $form; } #Drupal #Forms


Define a custom route in your module's routing file: my_module.custom_page: path: '/custom-page' defaults: _controller: '\Drupal\my_module\Controller\MyController::content' #Drupal #Routing


Retrieve user field values programmatically: $user = \Drupal\user\Entity\User::load($uid); $field_value = $user->get('field_my_field')->value; #Drupal #UserFields


Create a custom block in Drupal: class MyCustomBlock extends BlockBase { public function build() { return ['#markup' => t('Hello, Drupal!')]; } }


United States Trends

Loading...

Something went wrong.


Something went wrong.