[Drupal7] Adding new dependency to solr facets

Hello, 

here are the steps to add new dependency criteria for the facet on Drupal V7.

This post requires basic familiarity with Drupal development and understanding the integration with solr search and facetapi module. 

The dependency of facets is some conditions that are tested to display the facet or not. 

Facets are those controls displayed in the search for to refine the results scope.

There can be more than one dependency, the results of each dependency checks are anded to make the final decision whether to hide or show it. 

Dependency checks that return nulls are not considered. 

Basically there are three steps. 

For example, if we want to display the facet for the user called Maryam, hide it for the user Mohamad and for others we don't care. 

1-Create the category link for the settings page. 

function my_module_facetapi_facet_info_alter(&$facet_info, $searcher_info) {
    foreach ($facet_info as &$facet) {
        $facet['dependency plugins'][] = 'user_name';
    }
}
function my_module_facetapi_dependencies {
    return array(
        'user_name' => array(
            'handler' => array(
                'label' => t('User Name'),
                'class' => 'FacetapiDependencyName',
            ),
        ),
    );
}

2-Create the class handling the dependency logic and the settings form. 

class FacetapiDependencyName extends FacetapiDependency{
    public function execute{
       // Here we do the checks and return the value based on our logic
    }

    public function settingsForm(&$form, &$form_state){
       // Here we generate the settings form to take required input depending on the logic
       // for example take the names to display the facet to
    }
}

3-Implement the execute function that returns whether the dependency has been met (true) or not met (false) or we don't care (null)

public function execute{
    // Here we do the checks and return the value based on our logic global $user;
    if ($user->name == 'Maryam') return true;
    if ($user->name == 'Mohamad') return false;
    return;
}