Skip to content

Instantly share code, notes, and snippets.

@Cyberschorsch
Cyberschorsch / views_flag_context.info
Last active December 15, 2015 12:59
Views Flag Context
name = Views Flag Context
description = Provides a flag context.
core = 7.x
package = Flags
version = 7.x-0.1
dependencies[] = flag
files[] = handlers/views_argument_default_flag.inc
@Cyberschorsch
Cyberschorsch / views_flag_context.module
Last active December 15, 2015 12:58
hook_views_api()
<?php
/**
* Implements hook_views_api().
*/
function views_flag_context_views_api() {
return array(
'api' => '3',
);
}
@Cyberschorsch
Cyberschorsch / views_flag_context.views.inc.php
Last active December 15, 2015 12:59
hook_views_plugins().
<?php
/**
* Implements hook_views_plugins().
*/
function views_flag_context_views_plugins() {
$plugin = array(
'argument default' => array(
'views_argument_default_flag' => array(
'title' => t('Default Flags'),
'handler' => 'views_argument_default_flag',
@Cyberschorsch
Cyberschorsch / gist:5264038
Created March 28, 2013 15:24
Views Argument Default Flag Handler - RAW
<?php
/**
* Define the options form to enable selection of flags.
*/
function options_form(&$form, &$form_state) {
}
/**
* Return all possible options for the view and provide default values.
@Cyberschorsch
Cyberschorsch / gist:5264049
Created March 28, 2013 15:26
Views Argument Handler default value for options
<?php
'#default_value' => $this->options['flags'],
?>
@Cyberschorsch
Cyberschorsch / gist:5264059
Created March 28, 2013 15:27
Complete Option Form
<?php
/**
* Define the options form to enable selection of flags.
*/
function options_form(&$form, &$form_state) {
// Load all flags and types of each flag.
$flags = flag_get_flags('taxonomy_term');
// Combine all types (=vocabs) into one option array.
$flag_types = array();
@Cyberschorsch
Cyberschorsch / gist:5264081
Created March 28, 2013 15:29
The option definition
<?php
/**
* Return all possible options for the view and provide default values.
*/
function option_definition() {
$options = parent::option_definition();
$options['flags'] = array('default' => array());
$options['vocabularies'] = array('default' => array());
$options['fallback'] = array('default' => 'all');
$options['multiple_operator'] = array('default' => '+');
@Cyberschorsch
Cyberschorsch / gist:5264086
Created March 28, 2013 15:29
Submit Function
<?php
/**
* Provide the default form form for submitting options.
*/
function options_submit(&$form, &$form_state, &$options = array()) {
// We filter the options on only selected ones.
$options['flags'] = array_filter($options['flags']);
$options['vocabularies'] = array_filter($options['vocabularies']);
}
@Cyberschorsch
Cyberschorsch / gist:5264112
Created March 28, 2013 15:32
The get argument function
<?php
/**
* This function controls what to return to the contextual filter.
*/
function get_argument() {
// Get available flag types from the system.
$flags = flag_get_flags('taxonomy_term');
// Get all User flags.
$user_flags = flag_get_user_flags('taxonomy_term');
@Cyberschorsch
Cyberschorsch / gist:5264117
Last active December 15, 2015 12:59
Helper function for the module file
<?php
/**
* Helper to filter tids on given vocabularies.
*
* @param array $tids
* array of term ids
* @param array $vocabularies
* array of vocabulary machine names
*
* @return array