Skip to content

Commit

Permalink
CAPx-257 CAPx-258 Added page titles and helper block (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherakama authored Jan 23, 2017
1 parent 475d7f8 commit 766fc4d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 19 deletions.
61 changes: 50 additions & 11 deletions modules/capx_filters/capx_filters.forms.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function capx_filters_build_form($action, $importer, $filter_id = -1) {
* @return array
* The form array.
*/
function capx_filters_list($form, &$form_state, CFEntity $importer, $filter_id = NULL) {
function capx_filters_list(array $form, array &$form_state, CFEntity $importer, $filter_id = NULL) {
// Set the page title.
drupal_set_title($importer->title . " Filters");

Expand Down Expand Up @@ -111,7 +111,7 @@ function capx_filters_list($form, &$form_state, CFEntity $importer, $filter_id =
* @param array $form_state
* The form state array from submission.
*/
function capx_filters_list_submit($form, &$form_state) {
function capx_filters_list_submit(array $form, array &$form_state) {

// Set a global variable so that other hooks can patch up the entity save.
global $_capx_filters_updated;
Expand Down Expand Up @@ -139,7 +139,7 @@ function capx_filters_list_submit($form, &$form_state) {
* @return array
* The form array.
*/
function capx_filters_edit($form, &$form_state, CFEntity $importer, $filter_id = -1) {
function capx_filters_edit(array $form, array &$form_state, CFEntity $importer, $filter_id = -1) {
$key = '';
$value = '';
$comparison = '=';
Expand All @@ -153,12 +153,30 @@ function capx_filters_edit($form, &$form_state, CFEntity $importer, $filter_id =
$value = $filter['value'];
$comparison = $filter['comparison'];
$exclude = $filter['exclude'];

drupal_set_title(t('!importer Filter #!id', array(
'!importer' => $importer->label(),
'!id' => $filter_id + 1,
)));
}
else {
drupal_not_found();
drupal_exit();
}
}
else {
drupal_set_title(t('Add Filter to !importer', array('!importer' => $importer->label())));
}

$breadcrumbs = array(
l(t('Home'), '/'),
l(t('Administration'), '/admin'),
l(t('Configuration'), '/admin/config'),
l(t('CAPx'), '/admin/config/capx'),
l(t('Import'), '/admin/config/capx/import'),
l(t($importer->label()), '/admin/config/capx/importer/' . $importer->getMachineName() . '/filters'),
);
drupal_set_breadcrumb($breadcrumbs);

// Filter exists and is valid. Carry on and generate a form.
$form = array();
Expand Down Expand Up @@ -217,8 +235,17 @@ function capx_filters_edit($form, &$form_state, CFEntity $importer, $filter_id =
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#name' => 'submit',
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#name' => 'cancel',
);

$form['#attached']['js'][] = drupal_get_path('module', 'stanford_capx') . '/js/stanford_capx.mapper.form.js';
$form['#attached']['css'][] = drupal_get_path('module', 'capx_filters') . '/css/capx_filters.css';
$form['#attributes'] = array('id' => array('stanford-capx-mapper-form'));
return $form;
}

Expand All @@ -232,7 +259,11 @@ function capx_filters_edit($form, &$form_state, CFEntity $importer, $filter_id =
* @param array $form_state
* The form state array.
*/
function capx_filters_edit_validate($form, &$form_state) {
function capx_filters_edit_validate(array $form, array &$form_state) {
if ($form_state['clicked_button']['#name'] == 'cancel') {
return;
}

if ($form_state['values']['comparison'] == 'before' || $form_state['values']['comparison'] == 'after') {
$date = capx_filters_parse_date($form_state['values']['value']);
if (!$date) {
Expand All @@ -244,13 +275,18 @@ function capx_filters_edit_validate($form, &$form_state) {
/**
* Saves the filter to the given CAPx Mapper.
*/
function capx_filters_edit_submit($form, &$form_state) {
function capx_filters_edit_submit(array $form, array &$form_state) {
/** @var CFEntity $importer */
$importer = $form_state['build_info']['args'][0];

if ($form_state['clicked_button']['#name'] == 'cancel') {
$form_state['redirect'] = CAPX_FILTERS_PAGE . "/{$importer->getMachineName()}/filters";
return;
}

global $_capx_filters_updated;
$_capx_filters_updated = TRUE;

// @var CFEntity $importer.
$importer = $form_state['build_info']['args'][0];

$filter = array(
'key' => $form_state['values']['key'],
'value' => strtolower($form_state['values']['value']),
Expand Down Expand Up @@ -294,8 +330,11 @@ function capx_filters_edit_submit($form, &$form_state) {
* @return array
* The form array.
*/
function capx_filters_delete($form, &$form_state, CFEntity $importer, $filter_id) {

function capx_filters_delete(array $form, array &$form_state, CFEntity $importer, $filter_id) {
drupal_set_title(t('Delete Filter #!id from !label?', array(
'!id' => $filter_id + 1,
'!label' => $importer->label(),
)));
$form = array();
$form['disclaimer'] = array(
'#markup' => t('Are you sure you wish to delete this filter? This action cannot be undone'),
Expand Down Expand Up @@ -330,7 +369,7 @@ function capx_filters_delete($form, &$form_state, CFEntity $importer, $filter_id
/**
* Removes the filter from the CAPx mapper settings array.
*/
function capx_filters_delete_submit($form, &$form_state) {
function capx_filters_delete_submit(array $form, array &$form_state) {

// Used in entity save functions elsewhere.
global $_capx_filters_updated;
Expand Down
10 changes: 10 additions & 0 deletions modules/capx_filters/capx_filters.module
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,13 @@ function capx_filters_entity_presave($entity, $type) {

}
}

/**
* Implements hook_page_alter().
*/
function capx_filters_page_alter(&$page) {
if (isset($page['content']['system_main']['#form_id']) && $page['content']['system_main']['#form_id'] == 'capx_filters_edit') {
$block = block_load('stanford_capx', 'data_browser_launch');
$page['content']['data_browser_launch'] = _block_get_renderable_array(_block_render_blocks(array($block)));
}
}
10 changes: 10 additions & 0 deletions modules/capx_filters/css/capx_filters.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#block-system-main {
float: left;
width: 50%;
}

#block-stanford-capx-data-browser-launch {
float: right;
width: 50%;
overflow-y: scroll;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function capx_filters_views_default_views_alter(&$views) {

// Add the filters link field to the view and patch it in to the global
// re-write field so that the view has the filters link on it.

// Fetch the handler.
$handler = &$views['capx_importers']->display['default']->handler;

Expand Down
14 changes: 7 additions & 7 deletions modules/capx_filters/views/views_handler_filters_link.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
class views_handler_filters_link extends views_handler_field_entity {

/**
* @see parent
* {@inheritdoc}
*/
function option_definition() {
public function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}

/**
* @see parent
* {@inheritdoc}
*/
function options_form(&$form, &$form_state) {
public function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
Expand All @@ -39,9 +39,9 @@ class views_handler_filters_link extends views_handler_field_entity {
}

/**
* @see parent
* {@inheritdoc}
*/
function render($values) {
public function render($values) {
if ($entity = $this->get_value($values)) {
return $this->render_link($entity);
}
Expand All @@ -56,7 +56,7 @@ class views_handler_filters_link extends views_handler_field_entity {
* @return string
* The url to the filters edit page.
*/
function render_link($importer) {
public function render_link($importer) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "admin/config/capx/importer/" . $importer->getMachineName() . '/filters';
$text = !empty($this->options['text']) ? $this->options['text'] : t('Filters');
Expand Down

0 comments on commit 766fc4d

Please sign in to comment.