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_element_info_alter(). | |
*/ | |
function scholarrx_user_registration_element_info_alter(array &$info) { | |
$info['password_confirm']['#process'][] = 'scholarrx_process_password_confirm'; | |
} | |
function scholarrx_process_password_confirm(&$element, FormStateInterface $form_state, &$complete_form) { |
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 all licenses for current user that grant a specific license | |
$existing = $this->entityTypeManager->getStorage('commerce_license') | |
->loadByProperties([ | |
'license_role' => 'machine_name_of_role', | |
'uid' => \Drupal::current_user()->id() | |
]); |
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\free_trial; | |
use Drupal\Core\Entity\EntityTypeManager; | |
use Drupal\user\RoleInterface; | |
/** | |
* Class CreateLicense. | |
*/ | |
class CreateLicense implements CreateLicenseInterface { |
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\require_login\EventSubscriber; | |
use Drupal\Component\Serialization\Json; | |
use Drupal\Core\Config\ConfigFactory; | |
use Drupal\Core\Path\PathValidator; | |
use Drupal\Core\Routing\CurrentRouteMatch; | |
use Drupal\Core\Session\AccountInterface; | |
use Drupal\Core\Url; |
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 | |
/** | |
* snippets for dealing with custom entities | |
* Use dependency injection in actual code | |
*/ | |
function d8_custom_entity_new_entity_form() { | |
$entity = \Drupal::entityTypeManager() | |
->getStorage('the_entity_type') | |
->create() | |
->setOwnerId(\Drupal::currentUser()->id()); |
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
{% set has_bg_colour = paragraph.field_background_colour.value %} | |
{# | |
We are going to check here if the paragraph bundle has a background colour | |
set. If so, we apply that background colour as a class on that paragraph bundle. | |
Then, if it has a background colour, we decide that we want to give it some | |
padding, so we also add a .has-bg class to it. If individual paragraph bundles | |
need to override that, we can use removceClass on their paragraph.html.twig files. | |
#} |
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\mymodule\Plugin\Field\FieldWidget; | |
use Drupal\telephone\Plugin\Field\FieldWidget\TelephoneDefaultWidget; | |
/** | |
* Plugin implementation of the 'telephone_input_mask' widget. | |
* | |
* @FieldWidget( |
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 | |
/** | |
* Two hooks are necessary for adding an extra field to an entity display | |
*/ | |
/** | |
* Implements hook_entity_view(). | |
* Define the content that should be shown | |
*/ | |
function hook_entity_view($entity, $type, $view_mode, $langcode) { |
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_field_extra_fields(). | |
* Add the code to Registration enabled entities | |
*/ | |
function my_module_field_extra_fields() { | |
$extra = []; | |
foreach (entity_get_info() as $entity_type => $entity_info) { | |
foreach (array_keys($entity_info['bundles']) as $bundle) { |
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
/** | |
* Use | |
* | |
* $header['row1'][] => ['data' => 'header-1-1', 'colspan' => 2]; | |
* $header['row1'][] => ['data' => 'header-1-2', 'colspan' => 2]; | |
* $header['row2'] => ['Total', 'Avg', 'Total', 'Avg']; | |
* // add in some colgroups for targeted styling | |
* $colgroups = array_fill(0, 2, ['attributes' => ['span' => 2]]); | |
* $rows = array_fill(0, 4, '10'); | |
* |