Repository URL to install this package:
|
Version:
2.0.2 ▾
|
novicell/custom_forms
/
custom_forms.api.php
|
|---|
<?php
/**
* @file
* Hooks provided by Custom Forms module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Preprocess the field rendering of a custom forms form item.
*
* This hook allows modules to preprocess the field rendering of a custom forms
* form item. This is useful if you, for example, need to add more information
* to custom forms form item's field rendering (such as classes, states, etc.).
*
* @param array $element
* The custom forms form item's field render array.
*
* @param \Drupal\custom_forms\CustomFormItem $item
* The custom form item the render array belongs to.
*
* @ingroup hooks
*/
function hook_preprocess_custom_forms__form_item(&$element, \Drupal\custom_forms\CustomFormItem $item) {
$type = $item->getType();
$key = '#attributes';
// We need a different attribute key for those where we want it added to their wrapper.
$wrapper_elements = ['dawa_address', 'text_plain', 'email', 'number'];
if ($type === 'field' || in_array($item->getPluginDefinition()['id'], $wrapper_elements)) {
$key = '#wrapper_attributes';
}
if (!empty($element[$key])) {
if (is_array($element[$key])) {
$element[$key]['class'][] = 'custom-forms-item__'.$type;
$element[$key]['class'][] = 'js-custom-forms-item__'.$type;
} else if ($element[$key] instanceof \Drupal\Core\Template\Attribute) {
$element[$key]->addClass('custom-forms-item__'.$type);
$element[$key]->addClass('js-custom-forms-item__'.$type);
}
} else {
$element[$key] = [
'class' => [
'custom-forms-item__'.$type,
'js-custom-forms-item__'.$type,
],
];
}
}
/**
* Alter the operations for each custom form item.
*
* This hook allows modules to alter the operations available to each custom
* form item. For example, it can be used to add additional operations to each
* item that links to additional functionality, or removing existing operations
* that shouldn't be available to specific items.
*
* The hook supplies the custom form item, which allows access to all the item's
* functionality and information should it be needed.
*
* @param array $operations
* The operations array of operations for the custom form item.
*
* @param \Drupal\custom_forms\CustomFormItem $item
* The custom form item the operations array belongs to.
*
* @ingroup hooks
*/
function hook_states_custom_forms_item_operations_alter(array &$operations, \Drupal\custom_forms\CustomFormItem $item) {
$operations['states'] = [
'title' => t('States'),
'url' => \Drupal\Core\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' => \Drupal\Component\Serialization\Json::encode([
'width' => '500px'
]),
],
];
}
/**
* @} End of "addtogroup hooks".
*/