This file contains hidden or 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 | |
*/ | |
/** | |
* Implements hook_form_alter() | |
*/ | |
// Add unique form ID to theme suggestions for form elements. |
This file contains hidden or 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 | |
/* | |
* Place this file at src/Commands/MigrateEntityReference.php in your custom module directory. | |
*/ | |
namespace Drupal\exmample\Commands; | |
use Drupal\Core\Entity\EntityFieldManagerInterface; | |
use Drupal\Core\Entity\EntityTypeBundleInfoInterface; |
This file contains hidden or 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\example\Form; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
use Drupal\Core\Form\ConfigFormBase; | |
use Drupal\Core\Form\FormStateInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\HttpFoundation\RequestStack; |
This file contains hidden or 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\my_module\Plugin\QueueWorker\MyModuleQueueEvent. | |
*/ | |
namespace Drupal\my_module\Plugin\QueueWorker; | |
use Drupal\Core\Queue\QueueWorkerBase; |
This file contains hidden or 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\Service; | |
use Drupal\Core\Database\Driver\mysql\Connection; | |
/** | |
* Service that peforms administration work for My Module | |
* |
This file contains hidden or 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 | |
*/ | |
function my_module_preprocess_views_view(&$vars){ | |
// Only use unique IDs for view. | |
// Use this code for views with Better Exposed Filters. | |
if ($vars['view']->id() === 'view_name_bef') { | |
$rows = []; |
This file contains hidden or 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\Form\FormStateInterface; | |
/** | |
* Implements hook_form_alter() | |
*/ | |
function my_module_form_alter(&$form, FormStateInterface $form_state, $form_id) { | |
switch ($form_id) { | |
case 'views_exposed_form': |
This file contains hidden or 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 Symfony\Component\HttpFoundation\RedirectResponse; | |
/** | |
* Redirects with warning message | |
* | |
* When you need to redirect user upon a page load in procedural code. | |
* Otherwise, use the Controller response or ... | |
* ... $form_state->setRedirect('routing_machine_name'); return; |
This file contains hidden or 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\views\ViewExecutable; | |
/** | |
* Implements hook_views_pre_view(). | |
*/ | |
function my_module_views_pre_view(ViewExecutable $view, $display_id, array &$args) { | |
// Control access to specific view fields based on user role. | |
if ($view->id() == 'view_machine_name') { |
This file contains hidden or 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\views\ViewExecutable; | |
/** | |
* Implements hook_views_post_render(). | |
*/ | |
function my_module_views_post_render(ViewExecutable $view, &$output) { | |
if ($view->id() == 'view_machine_name') { | |
// Set title based on the user name of the current user profile. |
NewerOlder