Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/plugins/views_wizard/views_ui_base_views_wizard.class.php | ||
---|---|---|
9 | 9 |
* Defines a common interface for Views Wizard plugins. |
10 | 10 |
*/ |
11 | 11 |
interface ViewsWizardInterface { |
12 |
|
|
13 |
/** |
|
14 |
* Constructor. |
|
15 |
*/ |
|
12 | 16 |
function __construct($plugin); |
13 | 17 |
|
14 | 18 |
/** |
... | ... | |
31 | 35 |
* @throws ViewsWizardException in the event of a problem. |
32 | 36 |
*/ |
33 | 37 |
function create_view($form, &$form_state); |
38 |
|
|
34 | 39 |
} |
35 | 40 |
|
36 | 41 |
/** |
... | ... | |
43 | 48 |
* A very generic Views Wizard class - can be constructed for any base table. |
44 | 49 |
*/ |
45 | 50 |
class ViewsUiBaseViewsWizard implements ViewsWizardInterface { |
51 |
|
|
46 | 52 |
protected $base_table; |
47 | 53 |
protected $entity_type; |
48 | 54 |
protected $entity_info = array(); |
... | ... | |
87 | 93 |
|
88 | 94 |
$form['displays']['page'] = array( |
89 | 95 |
'#type' => 'fieldset', |
90 |
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
|
|
96 |
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend')), |
|
91 | 97 |
'#tree' => TRUE, |
92 | 98 |
); |
93 | 99 |
$form['displays']['page']['create'] = array( |
... | ... | |
102 | 108 |
// can be hidden en masse when the "Create a page" checkbox is unchecked. |
103 | 109 |
$form['displays']['page']['options'] = array( |
104 | 110 |
'#type' => 'container', |
105 |
'#attributes' => array('class' => array('options-set'),),
|
|
111 |
'#attributes' => array('class' => array('options-set')), |
|
106 | 112 |
'#dependency' => array( |
107 | 113 |
'edit-page-create' => array(1), |
108 | 114 |
), |
... | ... | |
224 | 230 |
|
225 | 231 |
$form['displays']['block'] = array( |
226 | 232 |
'#type' => 'fieldset', |
227 |
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend'),),
|
|
233 |
'#attributes' => array('class' => array('views-attachment', 'fieldset-no-legend')), |
|
228 | 234 |
'#tree' => TRUE, |
229 | 235 |
); |
230 | 236 |
$form['displays']['block']['create'] = array( |
... | ... | |
238 | 244 |
// can be hidden en masse when the "Create a block" checkbox is unchecked. |
239 | 245 |
$form['displays']['block']['options'] = array( |
240 | 246 |
'#type' => 'container', |
241 |
'#attributes' => array('class' => array('options-set'),),
|
|
247 |
'#attributes' => array('class' => array('options-set')), |
|
242 | 248 |
'#dependency' => array( |
243 | 249 |
'edit-block-create' => array(1), |
244 | 250 |
), |
... | ... | |
334 | 340 |
} |
335 | 341 |
|
336 | 342 |
/** |
337 |
* Build the part of the form that allows the user to select the view's filters.
|
|
343 |
* Build the part of the form that allows the user to select the filters. |
|
338 | 344 |
* |
339 | 345 |
* By default, this adds "of type" and "tagged with" filters (when they are |
340 | 346 |
* available). |
... | ... | |
344 | 350 |
$fields = views_fetch_fields($this->base_table, 'filter'); |
345 | 351 |
|
346 | 352 |
$entity_info = $this->entity_info; |
347 |
// If the current base table support bundles and has more than one (like user). |
|
353 |
// If the current base table support bundles and has more than one (like |
|
354 |
// user). |
|
348 | 355 |
if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) { |
349 | 356 |
// Get all bundles and their human readable names. |
350 | 357 |
$options = array('all' => t('All')); |
... | ... | |
431 | 438 |
} |
432 | 439 |
|
433 | 440 |
/** |
434 |
* Build the part of the form that allows the user to select the view's sort order.
|
|
441 |
* Build the part of the form that allows the user to select the sort order. |
|
435 | 442 |
* |
436 | 443 |
* By default, this adds a "sorted by [date]" filter (when it is available). |
437 | 444 |
*/ |
... | ... | |
492 | 499 |
* arrays of options for that display. |
493 | 500 |
*/ |
494 | 501 |
protected function build_display_options($form, $form_state) { |
495 |
// Display: Master |
|
502 |
// Display: Master.
|
|
496 | 503 |
$display_options['default'] = $this->default_display_options($form, $form_state); |
497 | 504 |
$display_options['default'] += array( |
498 | 505 |
'filters' => array(), |
... | ... | |
501 | 508 |
$display_options['default']['filters'] += $this->default_display_filters($form, $form_state); |
502 | 509 |
$display_options['default']['sorts'] += $this->default_display_sorts($form, $form_state); |
503 | 510 |
|
504 |
// Display: Page |
|
511 |
// Display: Page.
|
|
505 | 512 |
if (!empty($form_state['values']['page']['create'])) { |
506 | 513 |
$display_options['page'] = $this->page_display_options($form, $form_state); |
507 | 514 |
|
508 |
// Display: Feed (attached to the page) |
|
515 |
// Display: Feed (attached to the page).
|
|
509 | 516 |
if (!empty($form_state['values']['page']['feed'])) { |
510 | 517 |
$display_options['feed'] = $this->page_feed_display_options($form, $form_state); |
511 | 518 |
} |
512 | 519 |
} |
513 | 520 |
|
514 |
// Display: Block |
|
521 |
// Display: Block.
|
|
515 | 522 |
if (!empty($form_state['values']['block']['create'])) { |
516 | 523 |
$display_options['block'] = $this->block_display_options($form, $form_state); |
517 | 524 |
} |
... | ... | |
573 | 580 |
* Add the array of display options to the view, with appropriate overrides. |
574 | 581 |
*/ |
575 | 582 |
protected function add_displays($view, $display_options, $form, $form_state) { |
576 |
// Display: Master |
|
583 |
// Display: Master.
|
|
577 | 584 |
$default_display = $view->new_display('default', 'Master', 'default'); |
578 | 585 |
foreach ($display_options['default'] as $option => $value) { |
579 | 586 |
$default_display->set_option($option, $value); |
580 | 587 |
} |
581 | 588 |
|
582 |
// Display: Page |
|
589 |
// Display: Page.
|
|
583 | 590 |
if (isset($display_options['page'])) { |
584 | 591 |
$display = $view->new_display('page', 'Page', 'page'); |
585 | 592 |
// The page display is usually the main one (from the user's point of |
... | ... | |
587 | 594 |
// so that new displays which are added later automatically inherit them. |
588 | 595 |
$this->set_default_options($display_options['page'], $display, $default_display); |
589 | 596 |
|
590 |
// Display: Feed (attached to the page) |
|
597 |
// Display: Feed (attached to the page).
|
|
591 | 598 |
if (isset($display_options['feed'])) { |
592 | 599 |
$display = $view->new_display('feed', 'Feed', 'feed'); |
593 | 600 |
$this->set_override_options($display_options['feed'], $display, $default_display); |
594 | 601 |
} |
595 | 602 |
} |
596 | 603 |
|
597 |
// Display: Block |
|
604 |
// Display: Block.
|
|
598 | 605 |
if (isset($display_options['block'])) { |
599 | 606 |
$display = $view->new_display('block', 'Block', 'block'); |
600 | 607 |
// When there is no page, the block display options should become the |
... | ... | |
622 | 629 |
$display_options['style_plugin'] = 'default'; |
623 | 630 |
$display_options['row_plugin'] = 'fields'; |
624 | 631 |
|
625 |
// Add a least one field so the view validates and the user has already a preview. |
|
626 |
// Therefore the basefield could provide 'defaults][field]' in it's base settings. |
|
627 |
// If there is nothing like this choose the first field with a field handler. |
|
632 |
// Add a least one field so the view validates and the user has already a |
|
633 |
// preview. Therefore the basefield could provide 'defaults][field]' in |
|
634 |
// it's base settings. If there is nothing like this choose the first field |
|
635 |
// with a field handler. |
|
628 | 636 |
$data = views_fetch_data($this->base_table); |
629 | 637 |
if (isset($data['table']['base']['defaults']['field'])) { |
630 | 638 |
$field = $data['table']['base']['defaults']['field']; |
... | ... | |
682 | 690 |
} |
683 | 691 |
} |
684 | 692 |
$table_data = views_fetch_data($table); |
685 |
// Check whether the bundle key filter handler is or an child of it views_handler_filter_in_operator |
|
686 |
// If it's not just use a single value instead of an array. |
|
693 |
// Check whether the bundle key filter handler is or an child of it |
|
694 |
// views_handler_filter_in_operator. If it's not just use a single value |
|
695 |
// instead of an array. |
|
687 | 696 |
$handler = $table_data[$bundle_key]['filter']['handler']; |
688 | 697 |
if ($handler == 'views_handler_filter_in_operator' || is_subclass_of($handler, 'views_handler_filter_in_operator')) { |
689 | 698 |
$value = drupal_map_assoc(array($form_state['values']['show']['type'])); |
... | ... | |
700 | 709 |
); |
701 | 710 |
} |
702 | 711 |
|
703 |
// @todo: Figure out why this isn't part of node_views_wizard.
|
|
712 |
// @todo Figure out why this isn't part of node_views_wizard. |
|
704 | 713 |
if (!empty($form_state['values']['show']['tagged_with']['tids'])) { |
705 | 714 |
$filters['tid'] = array( |
706 | 715 |
'id' => 'tid', |
... | ... | |
741 | 750 |
protected function default_display_sorts_user($form, $form_state) { |
742 | 751 |
$sorts = array(); |
743 | 752 |
|
744 |
// Don't add a sort if there is no form value or the user selected none as sort. |
|
753 |
// Don't add a sort if there is no form value or the user selected none as |
|
754 |
// sort. |
|
745 | 755 |
if (!empty($form_state['values']['show']['sort']) && $form_state['values']['show']['sort'] != 'none') { |
746 | 756 |
list($column, $sort) = explode(':', $form_state['values']['show']['sort']); |
747 | 757 |
// Column either be a column-name or the table-columnn-ame. |
... | ... | |
826 | 836 |
* so that new displays which the user adds later will be similar to this |
827 | 837 |
* one. |
828 | 838 |
* |
829 |
* @param $options |
|
839 |
* @param array $options
|
|
830 | 840 |
* An array whose keys are the name of each option and whose values are the |
831 | 841 |
* desired values to set. |
832 |
* @param $display |
|
842 |
* @param object $display
|
|
833 | 843 |
* The display which the options will be applied to. The default display |
834 | 844 |
* will actually be assigned the options (and this display will inherit |
835 | 845 |
* them) when possible. |
836 |
* @param $default_display |
|
846 |
* @param object$default_display
|
|
837 | 847 |
* The default display, which will store the options when possible. |
838 | 848 |
*/ |
839 | 849 |
protected function set_default_options($options, $display, $default_display) { |
... | ... | |
862 | 872 |
* the views wizard, then the view will wind up with the title stored as the |
863 | 873 |
* default (with the page and block both inheriting from it). |
864 | 874 |
* |
865 |
* @param $options |
|
875 |
* @param array $options
|
|
866 | 876 |
* An array whose keys are the name of each option and whose values are the |
867 | 877 |
* desired values. |
868 |
* @param $display |
|
878 |
* @param object $display
|
|
869 | 879 |
* The display which the options will apply to. It will get the options by |
870 | 880 |
* inheritance from the default display when possible. |
871 |
* @param $default_display |
|
881 |
* @param object $default_display
|
|
872 | 882 |
* The default display, from which the options will be inherited when |
873 | 883 |
* possible. |
874 | 884 |
*/ |
... | ... | |
918 | 928 |
* |
919 | 929 |
* @throws ViewsWizardException if the values have not been validated. |
920 | 930 |
*/ |
921 |
function create_view($form, &$form_state) { |
|
922 |
$view = $this->retrieve_validated_view($form, $form_state); |
|
923 |
if (empty($view)) { |
|
924 |
throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated')); |
|
925 |
} |
|
926 |
return $view; |
|
927 |
} |
|
931 |
function create_view($form, &$form_state) {
|
|
932 |
$view = $this->retrieve_validated_view($form, $form_state);
|
|
933 |
if (empty($view)) {
|
|
934 |
throw new ViewsWizardException(t('Attempted to create_view with values that have not been validated'));
|
|
935 |
}
|
|
936 |
return $view;
|
|
937 |
}
|
|
928 | 938 |
|
929 | 939 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules