New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some more flexibility is search results labels/icons (mostly in case of overrides) #12749

merged 1 commit into from Dec 8, 2015


None yet
3 participants

rtripault commented Nov 2, 2015

What does it do ?

In short, it allows server side values (icon/label) computation for "uber bar" search results.

Why is it needed ?

When you override the search bar (using a different processor) to allow search your own models, there is no way to return an icon nor a search type "label", due to those being "computed" client side (and overriding the Ext.Template seems complex... at least i did not find a convenient way to do so)

Steps to reproduce issue

This' gonna be tricky to explain, but let's give it a try (untested pseudo code, you might need to adjust)

  • create a plugin bound to OnManagerPageInit with the following content
 * @var modX $modx
 * @var array $scriptProperties
 * @event

Ext.onReady(function() {
    // Create a new "searchbar" instance with overridden connector/processor
    var search = new MODx.SearchBar; = 'path/to/your/processor'; = 'http://domain.tld/your-connector.php';'http://domain.tld/your-connector.php', true);

return '';
  • create your custom processor in 'path/to/your/processor.class.php'

 * A custom search processor to add system settings search
 * (you might need to require_once the original search processor)
class CustomSearch extends modSearchProcessor
    public function process()
        // Override to allow searching system settings
        $this->query = $this->getProperty('query');
        if (!empty($this->query)) {
            if (strpos($this->query, ':') === 0) {
                // upcoming "launch actions"
            } else {
                // Search elements & resources
                if ($this->modx->hasPermission('view_chunk')) {
                if ($this->modx->hasPermission('view_template')) {
                if ($this->modx->hasPermission('view_tv')) {
                if ($this->modx->hasPermission('view_snippet')) {
                if ($this->modx->hasPermission('view_plugin')) {
                if ($this->modx->hasPermission('view_user')) {

        return $this->outputArray($this->results);

    protected function searchSettings()
        $type = 'settings';

        $class = 'modSystemSetting';
        $c = $this->modx->newQuery($class);
            'key:LIKE' => '%' . $this->query . '%',


        $collection = $this->modx->getCollection($class, $c);
        /** @var modSystemSetting $record */
        foreach ($collection as $record) {
            $action = 'system/settings&ns=' . $record->get('namespace');
            $area = $record->get('area');
            if (!empty($area)) {
                $action .= "&area={$area}";
            $this->results[] = [
                'name' => $record->get('key') .' - '. $record->get('value'),
                '_action' => $action,
                'description' => $record->get('description'),
                'type' => $type,
                'icon' => 'gears',
                'label' => 'System Settings',

return 'CustomSearch';
  • search for system setting key you know, notice that without this patch, there are no label nor icon for the system setting results
  • apply this PR, search a system setting, and see the label/icon in search results

Screenshot of the search results (on a highly customized manager, sorry)

Related issue(s)/PR(s)

@Mark-H Mark-H added this to the v2.5.0-pl milestone Dec 1, 2015

@Mark-H Mark-H self-assigned this Dec 8, 2015


This comment has been minimized.


Mark-H commented Dec 8, 2015

Thanks @rtripault - included in 2.5!

@Mark-H Mark-H merged commit 6084d58 into modxcms:2.x Dec 8, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

@rtripault rtripault deleted the rtripault:search-results branch Dec 15, 2015


This comment has been minimized.

smaddock commented Dec 15, 2015

@rtripault the only error I found in your pseudo code is that the plugin has to fire OnBeforeManagerPageInit, not OnManagerPageInit. Otherwise it functions as-posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment