|
|
|
@@ -9,6 +9,10 @@
|
|
|
|
|
* Defines a common interface for Views Wizard plugins.
|
|
|
|
|
*/
|
|
|
|
|
interface ViewsWizardInterface {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*/
|
|
|
|
|
function __construct($plugin);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -31,6 +35,7 @@ interface ViewsWizardInterface {
|
|
|
|
|
* @throws ViewsWizardException in the event of a problem.
|
|
|
|
|
*/
|
|
|
|
|
function create_view($form, &$form_state);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -43,6 +48,7 @@ class ViewsWizardException extends Exception {
|
|
|
|
|
* A very generic Views Wizard class - can be constructed for any base table.
|
|
|
|
|
*/
|
|
|
|
|
class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
|
|
|
|
|
protected $base_table;
|
|
|
|
|
protected $entity_type;
|
|
|
|
|
protected $entity_info = array();
|
|
|
|
@@ -87,7 +93,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
|
|
|
|
|
$form['displays']['page'] = array(
|
|
|
|
|
'#type' => 'fieldset',
|
|
|
|
|
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
|
|
|
|
|
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend')),
|
|
|
|
|
'#tree' => TRUE,
|
|
|
|
|
);
|
|
|
|
|
$form['displays']['page']['create'] = array(
|
|
|
|
@@ -102,7 +108,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
// can be hidden en masse when the "Create a page" checkbox is unchecked.
|
|
|
|
|
$form['displays']['page']['options'] = array(
|
|
|
|
|
'#type' => 'container',
|
|
|
|
|
'#attributes' => array('class' => array('options-set'),),
|
|
|
|
|
'#attributes' => array('class' => array('options-set')),
|
|
|
|
|
'#dependency' => array(
|
|
|
|
|
'edit-page-create' => array(1),
|
|
|
|
|
),
|
|
|
|
@@ -224,7 +230,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
|
|
|
|
|
$form['displays']['block'] = array(
|
|
|
|
|
'#type' => 'fieldset',
|
|
|
|
|
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
|
|
|
|
|
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend')),
|
|
|
|
|
'#tree' => TRUE,
|
|
|
|
|
);
|
|
|
|
|
$form['displays']['block']['create'] = array(
|
|
|
|
@@ -238,7 +244,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
// can be hidden en masse when the "Create a block" checkbox is unchecked.
|
|
|
|
|
$form['displays']['block']['options'] = array(
|
|
|
|
|
'#type' => 'container',
|
|
|
|
|
'#attributes' => array('class' => array('options-set'),),
|
|
|
|
|
'#attributes' => array('class' => array('options-set')),
|
|
|
|
|
'#dependency' => array(
|
|
|
|
|
'edit-block-create' => array(1),
|
|
|
|
|
),
|
|
|
|
@@ -334,7 +340,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the part of the form that allows the user to select the view's filters.
|
|
|
|
|
* Build the part of the form that allows the user to select the filters.
|
|
|
|
|
*
|
|
|
|
|
* By default, this adds "of type" and "tagged with" filters (when they are
|
|
|
|
|
* available).
|
|
|
|
@@ -344,7 +350,8 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
$fields = views_fetch_fields($this->base_table, 'filter');
|
|
|
|
|
|
|
|
|
|
$entity_info = $this->entity_info;
|
|
|
|
|
// If the current base table support bundles and has more than one (like user).
|
|
|
|
|
// If the current base table support bundles and has more than one (like
|
|
|
|
|
// user).
|
|
|
|
|
if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) {
|
|
|
|
|
// Get all bundles and their human readable names.
|
|
|
|
|
$options = array('all' => t('All'));
|
|
|
|
@@ -431,7 +438,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the part of the form that allows the user to select the view's sort order.
|
|
|
|
|
* Build the part of the form that allows the user to select the sort order.
|
|
|
|
|
*
|
|
|
|
|
* By default, this adds a "sorted by [date]" filter (when it is available).
|
|
|
|
|
*/
|
|
|
|
@@ -492,7 +499,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
* arrays of options for that display.
|
|
|
|
|
*/
|
|
|
|
|
protected function build_display_options($form, $form_state) {
|
|
|
|
|
// Display: Master
|
|
|
|
|
// Display: Master.
|
|
|
|
|
$display_options['default'] = $this->default_display_options($form, $form_state);
|
|
|
|
|
$display_options['default'] += array(
|
|
|
|
|
'filters' => array(),
|
|
|
|
@@ -501,17 +508,17 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
$display_options['default']['filters'] += $this->default_display_filters($form, $form_state);
|
|
|
|
|
$display_options['default']['sorts'] += $this->default_display_sorts($form, $form_state);
|
|
|
|
|
|
|
|
|
|
// Display: Page
|
|
|
|
|
// Display: Page.
|
|
|
|
|
if (!empty($form_state['values']['page']['create'])) {
|
|
|
|
|
$display_options['page'] = $this->page_display_options($form, $form_state);
|
|
|
|
|
|
|
|
|
|
// Display: Feed (attached to the page)
|
|
|
|
|
// Display: Feed (attached to the page).
|
|
|
|
|
if (!empty($form_state['values']['page']['feed'])) {
|
|
|
|
|
$display_options['feed'] = $this->page_feed_display_options($form, $form_state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display: Block
|
|
|
|
|
// Display: Block.
|
|
|
|
|
if (!empty($form_state['values']['block']['create'])) {
|
|
|
|
|
$display_options['block'] = $this->block_display_options($form, $form_state);
|
|
|
|
|
}
|
|
|
|
@@ -573,13 +580,13 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
* Add the array of display options to the view, with appropriate overrides.
|
|
|
|
|
*/
|
|
|
|
|
protected function add_displays($view, $display_options, $form, $form_state) {
|
|
|
|
|
// Display: Master
|
|
|
|
|
// Display: Master.
|
|
|
|
|
$default_display = $view->new_display('default', 'Master', 'default');
|
|
|
|
|
foreach ($display_options['default'] as $option => $value) {
|
|
|
|
|
$default_display->set_option($option, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display: Page
|
|
|
|
|
// Display: Page.
|
|
|
|
|
if (isset($display_options['page'])) {
|
|
|
|
|
$display = $view->new_display('page', 'Page', 'page');
|
|
|
|
|
// The page display is usually the main one (from the user's point of
|
|
|
|
@@ -587,14 +594,14 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
// so that new displays which are added later automatically inherit them.
|
|
|
|
|
$this->set_default_options($display_options['page'], $display, $default_display);
|
|
|
|
|
|
|
|
|
|
// Display: Feed (attached to the page)
|
|
|
|
|
// Display: Feed (attached to the page).
|
|
|
|
|
if (isset($display_options['feed'])) {
|
|
|
|
|
$display = $view->new_display('feed', 'Feed', 'feed');
|
|
|
|
|
$this->set_override_options($display_options['feed'], $display, $default_display);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display: Block
|
|
|
|
|
// Display: Block.
|
|
|
|
|
if (isset($display_options['block'])) {
|
|
|
|
|
$display = $view->new_display('block', 'Block', 'block');
|
|
|
|
|
// When there is no page, the block display options should become the
|
|
|
|
@@ -622,9 +629,10 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
$display_options['style_plugin'] = 'default';
|
|
|
|
|
$display_options['row_plugin'] = 'fields';
|
|
|
|
|
|
|
|
|
|
// Add a least one field so the view validates and the user has already a preview.
|
|
|
|
|
// Therefore the basefield could provide 'defaults][field]' in it's base settings.
|
|
|
|
|
// If there is nothing like this choose the first field with a field handler.
|
|
|
|
|
// Add a least one field so the view validates and the user has already a
|
|
|
|
|
// preview. Therefore the basefield could provide 'defaults][field]' in
|
|
|
|
|
// it's base settings. If there is nothing like this choose the first field
|
|
|
|
|
// with a field handler.
|
|
|
|
|
$data = views_fetch_data($this->base_table);
|
|
|
|
|
if (isset($data['table']['base']['defaults']['field'])) {
|
|
|
|
|
$field = $data['table']['base']['defaults']['field'];
|
|
|
|
@@ -682,8 +690,9 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$table_data = views_fetch_data($table);
|
|
|
|
|
// Check whether the bundle key filter handler is or an child of it views_handler_filter_in_operator
|
|
|
|
|
// If it's not just use a single value instead of an array.
|
|
|
|
|
// Check whether the bundle key filter handler is or an child of it
|
|
|
|
|
// views_handler_filter_in_operator. If it's not just use a single value
|
|
|
|
|
// instead of an array.
|
|
|
|
|
$handler = $table_data[$bundle_key]['filter']['handler'];
|
|
|
|
|
if ($handler == 'views_handler_filter_in_operator' || is_subclass_of($handler, 'views_handler_filter_in_operator')) {
|
|
|
|
|
$value = drupal_map_assoc(array($form_state['values']['show']['type']));
|
|
|
|
@@ -700,7 +709,7 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @todo: Figure out why this isn't part of node_views_wizard.
|
|
|
|
|
// @todo Figure out why this isn't part of node_views_wizard.
|
|
|
|
|
if (!empty($form_state['values']['show']['tagged_with']['tids'])) {
|
|
|
|
|
$filters['tid'] = array(
|
|
|
|
|
'id' => 'tid',
|
|
|
|
@@ -741,7 +750,8 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
protected function default_display_sorts_user($form, $form_state) {
|
|
|
|
|
$sorts = array();
|
|
|
|
|
|
|
|
|
|
// Don't add a sort if there is no form value or the user selected none as sort.
|
|
|
|
|
// Don't add a sort if there is no form value or the user selected none as
|
|
|
|
|
// sort.
|
|
|
|
|
if (!empty($form_state['values']['show']['sort']) && $form_state['values']['show']['sort'] != 'none') {
|
|
|
|
|
list($column, $sort) = explode(':', $form_state['values']['show']['sort']);
|
|
|
|
|
// Column either be a column-name or the table-columnn-ame.
|
|
|
|
@@ -826,14 +836,14 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
* so that new displays which the user adds later will be similar to this
|
|
|
|
|
* one.
|
|
|
|
|
*
|
|
|
|
|
* @param $options
|
|
|
|
|
* @param array $options
|
|
|
|
|
* An array whose keys are the name of each option and whose values are the
|
|
|
|
|
* desired values to set.
|
|
|
|
|
* @param $display
|
|
|
|
|
* @param object $display
|
|
|
|
|
* The display which the options will be applied to. The default display
|
|
|
|
|
* will actually be assigned the options (and this display will inherit
|
|
|
|
|
* them) when possible.
|
|
|
|
|
* @param $default_display
|
|
|
|
|
* @param object$default_display
|
|
|
|
|
* The default display, which will store the options when possible.
|
|
|
|
|
*/
|
|
|
|
|
protected function set_default_options($options, $display, $default_display) {
|
|
|
|
@@ -862,13 +872,13 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
* the views wizard, then the view will wind up with the title stored as the
|
|
|
|
|
* default (with the page and block both inheriting from it).
|
|
|
|
|
*
|
|
|
|
|
* @param $options
|
|
|
|
|
* @param array $options
|
|
|
|
|
* An array whose keys are the name of each option and whose values are the
|
|
|
|
|
* desired values.
|
|
|
|
|
* @param $display
|
|
|
|
|
* @param object $display
|
|
|
|
|
* The display which the options will apply to. It will get the options by
|
|
|
|
|
* inheritance from the default display when possible.
|
|
|
|
|
* @param $default_display
|
|
|
|
|
* @param object $default_display
|
|
|
|
|
* The default display, from which the options will be inherited when
|
|
|
|
|
* possible.
|
|
|
|
|
*/
|
|
|
|
@@ -918,12 +928,12 @@ class ViewsUiBaseViewsWizard implements ViewsWizardInterface {
|
|
|
|
|
*
|
|
|
|
|
* @throws ViewsWizardException if the values have not been validated.
|
|
|
|
|
*/
|
|
|
|
|
function create_view($form, &$form_state) {
|
|
|
|
|
$view = $this->retrieve_validated_view($form, $form_state);
|
|
|
|
|
if (empty($view)) {
|
|
|
|
|
throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated'));
|
|
|
|
|
}
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
function create_view($form, &$form_state) {
|
|
|
|
|
$view = $this->retrieve_validated_view($form, $form_state);
|
|
|
|
|
if (empty($view)) {
|
|
|
|
|
throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated'));
|
|
|
|
|
}
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|