Repository URL to install this package:
|
Version:
1.3.5 ▾
|
<?php
use Drupal\Component\Serialization\Json;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function custom_forms_states_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.custom_forms_states':
return 'Enables states functionality on custom forms.';
}
}
/**
* Implements hook_locale_translation_projects_alter().
*/
function custom_forms_states_locale_translation_projects_alter(&$projects) {
$module_handler = \Drupal::service('module_handler');
$path = $module_handler->getModule('custom_forms_states')->getPath();
$projects['custom_forms_states']['info']['interface translation server pattern'] = $path.'/translations/%language.po';
}
/**
* Implements hook_custom_forms_item_operations_alter().
*
* Add states operation to custom form entity.
*/
function custom_forms_states_custom_forms_item_operations_alter(array &$operations, \Drupal\custom_forms\CustomFormItem $item) {
$operations['states'] = [
'title' => t('States'),
'url' => Url::fromRoute('custom_form.field_list.item_states_form', ['custom_form' => $item->getFormId(), 'item' => $item->id()]),
'attributes' => [
'class' => [
'use-ajax'
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
'data-dialog-options' => Json::encode([
'width' => '500px'
]),
],
];
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Adds the additional library to the fields form.
*/
function custom_forms_states_form_custom_form_fields_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['#attached']['library'][] = 'custom_forms_states/states-ui';
}