abstract class flag_handler_relationship in Flag 6.2
Same name and namespace in other branches
- 7.3 includes/views/flag_handler_relationships.inc \flag_handler_relationship
- 7.2 includes/flag_handler_relationships.inc \flag_handler_relationship
Base class for all our relationship classes.
Hierarchy
- class \flag_handler_relationship extends \views_handler_relationship
Expanded class hierarchy of flag_handler_relationship
File
- includes/
flag_handler_relationships.inc, line 13 - Contains various relationship handlers.
View source
abstract class flag_handler_relationship extends views_handler_relationship {
/**
* Every relationship has a 'flag' option.
*/
function option_definition() {
$options = parent::option_definition();
$options['flag'] = array(
'default' => NULL,
);
$options['required'] = array(
'default' => 1,
);
return $options;
}
/**
* Make sure the flag exists.
*
* When importing views, or when deleting flags, inconsistent views may
* result. This validator is called by Views before saving or previewing a
* view.
*/
function validate() {
$errors = array();
$tokens = array(
'@relationship-name' => $this
->ui_name() . ' ' . $this
->admin_summary(),
'@flag-name' => $this->options['flag'],
);
if (!$this->options['flag']) {
$errors[] = t('You must pick a flag to use for the relationship "@relationship-name".', $tokens);
}
elseif (!flag_get_flag($this->options['flag'])) {
$errors[] = t('This view is looking for a flag by the name "@flag-name", but there is no such flag. Perhaps it was deleted. Please update the relationship "@relationship-name" in this view to use an existing flag.', $tokens);
}
return $errors;
}
function get_flag_type() {
return isset($this->definition['flag type']) ? $this->definition['flag type'] : NULL;
}
/**
* Returns the flag object.
*/
function get_flag() {
// Backward compatibility: There may exist old views on the system whose
// 'flag' option isn't set. (This happens if the admin had skippped
// clicking the 'Update' button.) When run, these views should behave as
// if the first flag was selected.
if (!isset($this->options['flag'])) {
$this->options['flag'] = flag_views_flag_default($this
->get_flag_type());
}
// Validation: Since validate() is called only when in Views's
// administrative UI, we need to do validation at "run time" ourselves.
if ($errors = $this
->validate()) {
foreach ($errors as $error) {
drupal_set_message($error, 'error');
}
}
return flag_get_flag($this->options['flag']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
flag_handler_relationship:: |
function | Returns the flag object. | ||
flag_handler_relationship:: |
function | |||
flag_handler_relationship:: |
function | Every relationship has a 'flag' option. | 1 | |
flag_handler_relationship:: |
function | Make sure the flag exists. |