protected function registerPlugin($name, $selector = null)
    {
        /** @var View $view */
        $view = $this->getView();

        MaterializePluginAsset::register($view);

        $id = $this->options['id'];

        if (is_null($selector)) {
            $selector = '#' . $id;
        }

        if ($this->clientOptions !== false) {
            $options = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);

            $js = "document.addEventListener('DOMContentLoaded', function() {M.$name.init(document.querySelectorAll('$selector'), $options);});";
            $view->registerJs($js, View::POS_END);
        }

        $this->registerClientEvents();
    }