function fe_paths_entity_edit_form in File Entity Paths 7.2
Form builder for File Entity Paths configuration add/edit form.
_state
Parameters
$form:
null $config:
Return value
mixed
2 string references to 'fe_paths_entity_edit_form'
- fe_paths_config_edit_page in ./
fe_paths.admin.inc - Page callback for configuration edit page.
- fe_paths_menu in ./
fe_paths.module - Implements hook_menu().
File
- ./
fe_paths.admin.inc, line 81 - Admin ui for the File Entity Paths module.
Code
function fe_paths_entity_edit_form($form, &$form_state, $config = NULL) {
$file_entity_info = entity_get_info('file');
$entities = fe_paths_get_fieldable_entities();
$file_types = array();
$file_types_defaults = isset($config->data['file_entity']) ? $config->data['file_entity'] : array();
// The name of the entity, which is connected to this config. Can be changed by $form_state.
$entity_name = isset($config->data['entity']) ? $config->data['entity'] : NULL;
// Set $entity_name value own $form_state value, if exists. It means, the form
// is changed during ajax process.
$entity_name = isset($form_state['values']['data']['entity']) ? $form_state['values']['data']['entity'] : $entity_name;
foreach ($file_entity_info['bundles'] as $name => $bundle) {
$file_types[$name] = $bundle['label'];
}
// Add id to form when editing existing config.
if (!is_null($config)) {
$form['id'] = array(
'#type' => 'value',
'#value' => $config->id,
);
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => isset($config->label) ? $config->label : '',
'#required' => TRUE,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#title' => t('Machine name'),
'#default_value' => isset($config->machine_name) ? $config->machine_name : '',
'#machine_name' => array(
'exists' => 'fe_paths_check_machine_name',
),
);
$form['path_name'] = array(
'#type' => 'fieldset',
'#title' => t('Path and filename settings'),
'path' => array(
'#type' => 'textfield',
'#title' => t("Path"),
'#description' => t('The path applied after the scheme://. It means, if the file has scheme "public", and this field is set as "foo", the file will be moved to the public://foo path. <strong>Do not use trailing slash at the end!</strong>'),
//'#element_validate' => array('token_element_validate'),
//'#token_types' => array('file', 'file'),
// Tmp disable until figure out, how to get the proper directory.
//'#field_prefix' => variable_get('file_public_path', conf_path() . '/files') . '/',
'#field_prefix' => "scheme://",
'#default_value' => isset($config->path) ? $config->path : '',
),
'filename' => array(
'#type' => 'textfield',
'#title' => t("Filename"),
'#description' => t('Set the filename pattern. This pattern will be validated based on parent entity settings. If settings is "global", all types of tokens are enabled. File tokens is always accepted. <strong>Do not use trailing slash in this field!</strong>'),
//'#element_validate' => array('token_element_validate'),
//'#token_types' => array('file', 'file'),
'#default_value' => isset($config->filename) ? $config->filename : '[file:name-only-original].[file:extension-original]',
),
'tokens' => array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'help' => array(
'#theme' => 'token_tree',
'#token_types' => array_keys($entities),
),
'#prefix' => '<div id="fe-paths-tokens">',
'#suffix' => '</div>',
),
);
$form['path_name']['transliteration'] = array(
'#type' => 'checkbox',
'#title' => t('Transliterate'),
'#default_value' => isset($config->data['transliteration']) ? $config->data['transliteration'] : FALSE,
'#description' => t('Use module !link to cleanup path and filename.', array(
'!link' => l(t('Transliteration'), 'http://drupal.org/project/transliteration', array(
'external' => TRUE,
)),
)),
'#parents' => array(
'data',
'transliteration',
),
);
if (!module_exists('transliteration')) {
$form['path_name']['transliteration']['#disabled'] = TRUE;
$form['path_name']['transliteration']['#default_value'] = 0;
}
$form['path_name']['pathauto'] = array(
'#type' => 'checkbox',
'#title' => t('Pathauto'),
'#default_value' => isset($config->data['pathauto']) ? $config->data['pathauto'] : FALSE,
'#description' => t('Use module !link to cleanup path and filename.', array(
'!link' => l(t('Pathauto'), 'http://drupal.org/project/pathauto', array(
'external' => TRUE,
)),
)),
'#parents' => array(
'data',
'pathauto',
),
);
if (!module_exists('pathauto')) {
$form['path_name']['pathauto']['#disabled'] = TRUE;
$form['path_name']['pathauto']['#default_value'] = 0;
}
$form['file_entity'] = array(
'#type' => 'fieldset',
'#title' => t('File types'),
'file_bundle' => array(
'#type' => 'checkboxes',
'#options' => $file_types,
'#description' => t('Choose, in which file types should this configuration be activated.'),
'#parents' => array(
'data',
'file_entity',
),
'#default_value' => $file_types_defaults,
),
);
$form['parent_entity'] = array(
'#type' => 'fieldset',
'#title' => t('Parent entity settings'),
'#tree' => TRUE,
'entity' => array(
'#type' => 'select',
'#title' => t('Choose entity'),
'#description' => t('Choose the parent entity. The parent entity determine, which type of tokens will be used in this config.'),
'#options' => array(
'global' => t('Global'),
) + $entities,
'#ajax' => array(
'callback' => 'fe_paths_add_bundle_settings',
'wrapper' => 'bundle-target',
),
'#parents' => array(
'data',
'entity',
),
'#default_value' => isset($config->data['entity']) ? $config->data['entity'] : 'global',
),
'bundle' => array(
'#tree' => TRUE,
'#type' => 'container',
'#attributes' => array(
'id' => 'bundle-target',
),
'#parents' => array(
'data',
'bundle',
),
),
);
if (!is_null($entity_name) && $entity_name != 'global') {
$bundles = fe_paths_get_bundle_names($entity_name);
// Only listed the bundles, in which proper field exists.
foreach ($bundles as $key => $bundle) {
$fields = fe_paths_get_available_fields($entity_name, $key);
if (empty($fields)) {
unset($bundles[$key]);
}
}
foreach ($bundles as $key => $bundle) {
$fields = fe_paths_get_available_fields($entity_name, $key);
$form['parent_entity']['bundle'][$key] = array(
'#type' => 'fieldset',
'#title' => check_plain($bundles[$key]),
);
foreach ($fields as $field_name => $field) {
$form['parent_entity']['bundle'][$key][$field_name] = array(
'#type' => 'checkbox',
'#title' => check_plain($field),
'#default_value' => isset($config->data['bundle'][$key][$field_name]) ? $config->data['bundle'][$key][$field_name] : FALSE,
);
}
}
}
$form['overrides'] = array(
'#type' => 'fieldset',
'#title' => t('Overrides'),
'other_config' => array(
'#type' => 'checkbox',
'#title' => t('Override by other configuration.'),
'#description' => t('Let other lower weight configuration to modify path provided by this configuration. This is independent of the <em>Override options</em> below. If this is checked, the lower weighted configuration will be always applied!'),
'#default_value' => isset($config->data['other_config']) ? $config->data['other_config'] : FALSE,
'#parents' => array(
'data',
'other_config',
),
),
'override_options' => array(
'#type' => 'radios',
'#title' => t('Override options'),
'#description' => t('This override setting define the behaviour of files, which are used more than one entities in the same time.
Set this to <em>Never</em> means, the path of the file will never be regenerated.
<em>Within the same entity type</em> means, if a file was uploaded to a user entity, and is used again in a node, the file path will not be overridden.
But if you upload the file to a node, and you use it again in other node, the new node tokens (if set) will be saved.
If settings <em>Within the same entity</em> is choosen, the file used in two different node will be not updated,
but if you set to change filename to node title, and the title is changed in the node, in which the file was originally uploaded,
the path will be changed to the new node title.'),
'#options' => fe_paths_get_override_options(),
'#default_value' => isset($config->data['override_options']) ? $config->data['override_options'] : FE_PATHS_OVERRIDE_NEVER,
'#parents' => array(
'data',
'override_options',
),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}