View source
<?php
class views_attach_plugin_display_profile extends views_plugin_display {
function option_definition() {
$options = parent::option_definition();
$options['weight'] = array(
'default' => 10,
);
$options['category'] = array(
'default' => NULL,
);
$options['default_argument'] = array(
'default' => 'uid',
);
return $options;
}
function options_summary(&$categories, &$options) {
parent::options_summary($categories, $options);
$categories['profile'] = array(
'title' => t('Profile settings'),
);
$category = $this
->get_option('category');
if (empty($category)) {
$category = t('Default');
}
$options['category'] = array(
'category' => 'profile',
'title' => t('Category'),
'value' => $category,
);
$weight = $this
->get_option('weight');
if (empty($weight)) {
$weight = 10;
}
$options['weight'] = array(
'category' => 'profile',
'title' => t('Weight'),
'value' => $weight,
);
$options['default_argument'] = array(
'category' => 'profile',
'title' => t('Default argument'),
'value' => $this
->get_option('default_argument') === 'uid' ? t('Yes') : t('No'),
);
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
switch ($form_state['section']) {
case 'weight':
$form['#title'] .= t('Weight');
$form['weight'] = array(
'#type' => 'weight',
'#description' => t('The position of this view in relation to other profile elements.'),
'#default_value' => $this
->get_option('weight'),
);
break;
case 'category':
$form['#title'] .= t('Category');
$form['category'] = array(
'#type' => 'textfield',
'#description' => t('The name of the profile tab this view should be listed in. If empty, it will be displayed on the main profile tab.'),
'#default_value' => $this
->get_option('category'),
);
break;
case 'default_argument':
$form['#title'] .= t('Default argument');
$form['default_argument'] = array(
'#type' => 'checkbox',
'#title' => t("Provide the current user id as a default argument."),
'#default_value' => $this
->get_option('default_argument') === 'uid',
'#return_value' => 'uid',
);
break;
}
}
function options_submit($form, &$form_state) {
parent::options_submit($form, $form_state);
switch ($form_state['section']) {
case 'weight':
$this
->set_option('weight', $form_state['values']['weight']);
break;
case 'category':
$this
->set_option('category', $form_state['values']['category']);
break;
case 'default_argument':
$this
->set_option('default_argument', $form_state['values']['default_argument']);
break;
}
}
function execute() {
$data = $this->view
->render();
if (!empty($this->view->result) || $this
->get_option('empty') || !empty($this->view->style_plugin->definition['even empty'])) {
return $data;
}
}
function uses_exposed() {
return FALSE;
}
}