Skip to content

Commit

Permalink
Not showing an empty fieldset when there are no datastreams to add.
Browse files Browse the repository at this point in the history
  • Loading branch information
willtp87 committed Feb 20, 2015
1 parent 8e4e83d commit 7573eff
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions builder/includes/datastream.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -200,36 +200,23 @@ function xml_form_builder_datastream_form_metadata_form_submit(array $form, arra
*/
function xml_form_builder_create_metadata_form($form, &$form_state, $object) {
form_load_include($form_state, 'inc', 'xml_form_builder', 'includes/datastream.form');
form_load_include($form_state, 'inc', 'xml_form_builder', 'includes/associations');
form_load_include($form_state, 'inc', 'islandora', 'includes/utilities');

$form_state['object_id'] = $object->id;
// Find all possible datastreams that don't already exist.
$datastreams = array();
foreach (islandora_get_datastreams_requirements($object) as $dsid => $datastream) {
if (!isset($object[$dsid])) {
$datastreams[] = $dsid;
}
}
// Find datastreams that associations exist for.
if (!empty($datastreams)) {
$options = array();
foreach (xml_form_builder_get_associations(array(), $object->models, $datastreams) as $key => $value) {
$options[$value['dsid']] = $value['dsid'];
}
if (!empty($options)) {
$form['dsid'] = array(
'#title' => t('Datastream ID'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Select the ID of a datastream to create new metadata.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('xml_form_builder_create_metadata_form_submit'),
'#value' => t('Create'),
);
}
$datastreams = xml_form_builder_empty_metadata_datastreams($object);
$options = array_combine($datastreams, $datastreams);
if ($options) {
$form_state['object_id'] = $object->id;
$form['dsid'] = array(
'#title' => t('Datastream ID'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Select the ID of a datastream to create new metadata.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('xml_form_builder_create_metadata_form_submit'),
'#value' => t('Create'),
);
}
return $form;
}
Expand All @@ -248,10 +235,30 @@ function xml_form_builder_add_datastream_page(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/add_datastream.form');
return array(
'core_form' => drupal_get_form('islandora_add_datastream_form', $object),
'xml_form_fieldset' => array(
'xml_form_fieldset' => xml_form_builder_empty_metadata_datastreams($object) ?
array(
'#type' => 'fieldset',
'#title' => t('Add A Metadata Datastream'),
'xml_form' => drupal_get_form('xml_form_builder_create_metadata_form', $object),
),
) :
array(),
);
}

/**
* Get empty metadata datastreams on an object.
*/
function xml_form_builder_empty_metadata_datastreams($object) {
module_load_include('inc', 'xml_form_builder', 'includes/associations');
$datastreams = array();
foreach (islandora_get_datastreams_requirements($object) as $dsid => $datastream) {
if (!isset($object[$dsid])) {
$datastreams[] = $dsid;
}
}
$filtered_datastreams = array();
foreach (xml_form_builder_get_associations(array(), $object->models, $datastreams) as $key => $value) {
$filtered_datastreams[] = $value['dsid'];
}
return $filtered_datastreams;
}

0 comments on commit 7573eff

Please sign in to comment.