function media_acquiadam_form_media_type_edit_form_alter in Media: Acquia DAM 8
Implements hook_form_FORM_ID_alter().
File
- ./
media_acquiadam.module, line 244 - Integrates Drupal with Acquia DAM.
Code
function media_acquiadam_form_media_type_edit_form_alter(&$form, FormStateInterface &$form_state) {
$form['#attached']['library'][] = 'media_acquiadam/asset_form';
// Add a field mapping to the entity publishing status if one doesn't exist.
$mappings =& $form['source_dependent']['field_map'];
if (!empty($mappings)) {
foreach (Element::children($mappings) as $key) {
// Sort fields with assigned mappings to the top to make it easier to
// identify what is and is not mapped at a glance.
// We need to set different weights based on if we're dealing with an
// XMP field or not.
$mappings[$key]['#weight'] = strpos($key, 'xmp_') === FALSE ? 0 : 100;
if (!empty($mappings[$key]['#default_value']) && $mappings[$key]['#default_value'] !== '_none') {
$mappings[$key]['#weight'] -= 10;
}
$options =& $mappings[$key]['#options'];
if (!isset($options['status'])) {
$options['status'] = t('Publishing status');
}
}
}
// Insert headline before first XMP field in the fieldset.
$mapping_keys = array_keys($mappings);
$xmp_keys = preg_grep('/xmp_.+/i', $mapping_keys);
reset($xmp_keys);
$offset = key($xmp_keys);
if ($offset) {
$xmp_header = [
'xmp_header' => [
'#type' => 'html_tag',
'#tag' => 'h4',
'#value' => t('Field Mapping: XMP Metadata'),
'#attributes' => [
'class' => 'fieldset-subhead',
],
],
];
array_splice($mappings, $offset, 0, $xmp_header);
}
}