uc_dropdown_test.module in Dropdown Attributes 8
A module used for testing uc_dropdown_attributes functionality.
File
uc_dropdown_test/uc_dropdown_test.moduleView source
<?php
/**
* @file
* A module used for testing uc_dropdown_attributes functionality.
*/
use Drupal\node\Entity\Node;
/**
* Implements hook_form_FORM_ID_alter() for uc_product_add_to_cart_form().
*/
function uc_dropdown_test_form_uc_product_add_to_cart_form_alter(&$form, $form_state) {
if (!isset($form['node'])) {
return;
}
$nid = $form['node']['#value']
->id();
$node = Node::load($nid);
if (!uc_product_is_product($nid) && 'product_kit' != $node
->getType()) {
return;
}
$type = '';
if ($node
->getType() == 'product_kit') {
foreach ($form['products'] as $key1 => $product) {
if (is_numeric($key1)) {
foreach ($product['attributes'] as $key2 => $child) {
if (is_numeric($key2)) {
if ($child['#title'] == 'Grandchild') {
$type = $child['#type'];
}
}
}
}
}
switch ($type) {
case 'select':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_select_kit';
break;
case 'radios':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_radios_kit';
break;
case 'checkboxes':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_checkboxes_kit';
break;
case 'textfield':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_textfield_kit';
break;
default:
break;
}
}
else {
foreach ($form['attributes'] as $key => $child) {
if (is_numeric($key)) {
if ($child['#title'] == 'Grandchild') {
$type = $child['#type'];
}
}
}
switch ($type) {
case 'select':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_select';
break;
case 'radios':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_radios';
break;
case 'checkboxes':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_checkboxes';
break;
case 'textfield':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_textfield';
break;
default:
break;
}
}
}
/**
* Implements hook_form_FORM_ID_alter() for uc_order_create_form().
*/
function uc_dropdown_test_form_uc_order_create_form_alter(&$form, $form_state) {
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_order_create';
}
/**
* Implements hook_form_FORM_ID_alter() for uc_order_edit_form().
*/
function uc_dropdown_test_form_uc_order_edit_form_alter(&$form, $form_state) {
if (!isset($form['products']['product_controls']['node'])) {
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_order_edit';
return;
}
$nid = $form['products']['product_controls']['nid']['#value'];
$node = Node::load($nid);
if (!uc_product_is_product($nid) && 'product_kit' != $node
->getType()) {
return;
}
$type = '';
if ($node
->getType() == 'product_kit') {
foreach ($form['products'] as $key1 => $product) {
if (is_numeric($key1)) {
foreach ($product['attributes'] as $key2 => $child) {
if (is_numeric($key2)) {
if ($child['#title'] == 'Grandchild') {
$type = $child['#type'];
}
}
}
}
}
switch ($type) {
case 'select':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_order_select_kit';
break;
case 'radios':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_order_radios_kit';
break;
case 'checkboxes':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_order_checkboxes_kit';
break;
case 'textfield':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_order_textfield_kit';
break;
default:
break;
}
}
else {
foreach ($form['products']['product_controls']['attributes'] as $key => $child) {
if (is_numeric($key)) {
if ($child['#title'] == 'Grandchild') {
$type = $child['#type'];
}
}
}
switch ($type) {
case 'select':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_select';
break;
case 'radios':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_radios';
break;
case 'checkboxes':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_checkboxes';
break;
case 'textfield':
$form['#attached']['library'][] = 'uc_dropdown_test/drupal.uc_dropdown_textfield';
break;
default:
break;
}
}
}
Functions
Name | Description |
---|---|
uc_dropdown_test_form_uc_order_create_form_alter | Implements hook_form_FORM_ID_alter() for uc_order_create_form(). |
uc_dropdown_test_form_uc_order_edit_form_alter | Implements hook_form_FORM_ID_alter() for uc_order_edit_form(). |
uc_dropdown_test_form_uc_product_add_to_cart_form_alter | Implements hook_form_FORM_ID_alter() for uc_product_add_to_cart_form(). |