Last active
August 22, 2017 18:09
-
-
Save daggerhart/8631f6a1142c6f860629a2149f8dcfc6 to your computer and use it in GitHub Desktop.
Drupal 7 & 8 - useful field info on field management form: required, file uri_scheme, filefield_paths. Drupal 8 version in first comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
* | |
* Indicate some details about the field on the field overview form | |
*/ | |
function MYMODULE_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) { | |
$instances = field_info_instances( $form['#entity_type'], $form['#bundle'] ); | |
$fields = field_info_fields(); | |
foreach( $instances as $field_name => $instance ){ | |
$field = $fields[ $field_name ]; | |
if ( !empty( $instance['required'] ) ) { | |
$form['fields'][ $field_name ]['label']['#markup'].= " <small style='color: darkred;'>-required-</small>"; | |
} | |
if ( !empty( $field['settings']['uri_scheme'] ) ){ | |
$path = "{$field['settings']['uri_scheme']}://"; | |
// filefield_paths module | |
if ( !empty( $instance['settings']['filefield_paths'] ) && $instance['settings']['filefield_paths_enabled'] ) { | |
if ( !empty( $instance['settings']['filefield_paths']['file_path']['value'] ) ){ | |
$path.= "{$instance['settings']['filefield_paths']['file_path']['value']}/"; | |
} | |
$path.= "{$instance['settings']['filefield_paths']['file_name']['value']}"; | |
if ( $instance['settings']['filefield_paths']['active_updating'] ) { | |
$path.= "<br>-active updating-"; | |
} | |
} | |
// core drupal | |
else { | |
$path.= "{$instance['settings']['file_directory']}/"; | |
} | |
$form['fields'][ $field_name ]['label']['#markup'].= "<br><small style='color: darkred;'>{$path}</small>"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Drupal 8 you need to take over the FieldConfigListBuilder:
mymodule/src/MyModuleFieldConfigListBuilder.php
mymodule/mymodule.module