By admin, 11 December, 2023 Add js library as "type: module" my-library: js: js/App.js: { attributes: { type: module } } Tags javascript libraries
By admin, 11 December, 2023 Check if module exists and enabled $moduleHandler = \Drupal::service('module_handler'); if ($moduleHandler->moduleExists('my_module')) { // Code Here. } Tags service module
By admin, 11 December, 2023 Inject module_handler service to form use Drupal\Core\Extension\ModuleHandlerInterface; /** * The module handler service. */ protected ModuleHandlerInterface $moduleHandler; /** * Constructs a form. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler Tags dependency injection
By admin, 9 December, 2023 Get database table column names $connection = Database::getConnection(); $fields = $connection->query("DESCRIBE `my_table`")->fetchAll(); foreach ($fields as $field) { if ($field->Field === 'column_name') { // Do something. } } Tags database
By admin, 9 December, 2023 Get module installed schema drush ev "echo \Drupal::service('update.update_hook_registry')->getInstalledVersion('my_module')" Tags drush schema
By admin, 9 December, 2023 Check if database table exists if (\Drupal::database()->schema()->tableExists('my_table')) { // Do something. } Tags database
By admin, 28 November, 2023 Install site via drush drush si standard --locale en --site-name=Test --site-mail=noreply@example.com --account-name=admin --account-pass=123 -y Tags drush
By admin, 27 November, 2023 Remove migration tables drush sqlq --extra='-ss' "show tables like 'migrate_%'" | sed -r '/^\s*$/d' | while read TABLE ; do echo "drush sqlq 'DROP TABLE $TABLE;'" ; done Tags drush migration
By admin, 23 November, 2023 Attach library to custom form /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['#attached'] = [ 'library' => ['my_module/my_library'], ]; return $form; } Tags form libraries
By admin, 15 November, 2023 Inject file.usage service to custom service use Drupal\file\FileUsage\DatabaseFileUsageBackend; /** * File usage service. */ protected DatabaseFileUsageBackend $fileUsage; /** * Constructs an object. * * @param \Drupal\file\FileUsage\DatabaseFileUsageBackend $file_usage * File usage service. */ Tags dependency injection file.usage service