Skip to content

Instantly share code, notes, and snippets.

@ozin7
ozin7 / Controller.php
Last active March 7, 2024 17:56
Drupal 8: Dependency injection in Service, Controller, Plugin, Deriver.
<?php
/**
* Controller. Implements ContainerInjectionInterface
*/
namespace Drupal\gurei\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\gurei\Service\CompanyService;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ozin7
ozin7 / third_party_settings.php
Created March 17, 2020 17:49
Drupal 8: How to add third party settings which will be saved automatically.
<?php
/**
* Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
*/
function datalayer_form_field_config_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$field = $form_state->getFormObject()->getEntity();
$form['third_party_settings']['datalayer']['label'] = [
'#type' => 'textfield',
'#title' => t('DataLayer label'),
'#default_value' => $field->getThirdPartySetting('datalayer', 'label', $field->get('field_name')),