1) Add new custom views filter handler that extends views_handler_filter_in_operator
class MY_MODULE_own_company_filter_handler extends views_handler_filter_in_operator {
public function get_value_options() {
$options = parent::get_value_options();
$options['own'] = 'Own Company';
$this->value_options = $options;
return $this->value_options;
}
/**
* Replaces "Own Company" value with real value.
* Do query alter here or in query() function.
*/
function pre_query() {
parent::pre_query();
// Check if "Own Company" was chosen.
if (!empty($this->value['own'])) {
// Unset "Own Company" 'own' value.
unset($this->value['own']);
// Get current "Own Company" value the way you like.
$company_id = 100500; // Example value.
// Set current "Own Company" value.
$this->value[$company_id] = $company_id;
}
}
}
2) Implement hook_views_data_alter() and add custom handler to all entityreference field filters
/**
* Implements hook_views_data_alter().
*/
function MY_MODULE_views_data_alter(&$data) {
// Loop all field filters.
foreach ($data as $data_key => $data_field) {
if (strpos($data_key, 'field_data_') !== FALSE) {
// Get field name
$field_name = str_replace('field_data_', '', $data_key);
// Check if field filter is entity reference
if (isset($data_field[$field_name . '_target_id']['filter']['handler'])) {
if ($data_field[$field_name . '_target_id']['filter']['handler'] == 'views_handler_filter_in_operator') {
// Name of custom handler class
$custom = 'MY_MODULE_own_company_filter_handler';
// Add custom handler
$data[$data_key][$field_name . '_target_id']['filter']['handler'] = $custom;
}
}
}
}
}