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
merged 1 commit into from Dec 8, 2015

Conversation

Projects
None yet
3 participants
@rtripault
Collaborator

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
<?php
/**
 * @var modX $modx
 * @var array $scriptProperties
 * 
 * @event
 */

$modx->controller->addHtml(<<<HTML
<script>
Ext.onReady(function() {
    // Create a new "searchbar" instance with overridden connector/processor
    var search = new MODx.SearchBar;
    search.store.baseParams.action = 'path/to/your/processor';
    search.store.url = 'http://domain.tld/your-connector.php';
    search.store.proxy.setUrl('http://domain.tld/your-connector.php', true);
});
</script>
HTML
);

return '';
  • create your custom processor in 'path/to/your/processor.class.php'
<?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"
                //$this->searchActions();
            } else {
                // Search elements & resources
                $this->searchResources();
                if ($this->modx->hasPermission('view_chunk')) {
                    $this->searchChunks();
                }
                if ($this->modx->hasPermission('view_template')) {
                    $this->searchTemplates();
                }
                if ($this->modx->hasPermission('view_tv')) {
                    $this->searchTVs();
                }
                if ($this->modx->hasPermission('view_snippet')) {
                    $this->searchSnippets();
                }
                if ($this->modx->hasPermission('view_plugin')) {
                    $this->searchPlugins();
                }
                if ($this->modx->hasPermission('view_user')) {
                    $this->searchUsers();
                }
                $this->searchSettings();
            }
        }

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

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

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

        $c->limit($this->maxResults);

        $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)
screenshot_2015-11-02_13-09-23

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

@Mark-H

This comment has been minimized.

Collaborator

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
Details

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

@smaddock

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