Handles [[Widget::EVENT_BEFORE_RUN]] event, registering related client script.
@param \yii\base\Event $event event instance.
7019
public function beforeRun($event)
    {
        $id = $this->owner->options['id'];
        $options = Json::htmlEncode($this->getClientOptions());
        $view = $this->owner->getView();
        GridViewAsset::register($view);
        $view->registerJs("jQuery('#$id').yiiGridView($options);");
    }
425273
public function beforeAction($event)
    {
        if (in_array($event->action->id, $this->actions) || in_array('*', $this->actions)) {
            $sender = $event->sender;
            $command = $sender->id . '/' . $sender->action->id . $this->getActionParams();
            $this->schedule = new CronScheduleModel();
            $this->schedule->startCronSchedule($command);
            $this->setupApplicationErrorHandlers();
        }
    }
898829
public function beforeFilter(Event $event)
    {
        $this->_controller->set('__commentComponentLoaded__', true);
        $this->_controller->set('_commentFormContext', $this->config('arrayContext'));
    }
881764
function handle(Event $event)
    {
        if ($this->accept($event)) {
            $this->onEvent($event);
            return true;
        }

        return false;
    }
625476
public function beforeFilter(\Cake\Event\Event $event)
    {
        // notifications for index-action have to be loaded here because of the loaded count of unread notifications.
        $this->set('notifications', $this->Notifier->getNotifications());
        $this->Notifier->markAsRead();

        parent::beforeFilter($event);
    }
659306
public function registerEvent($event, $callback)
    {
        $eventManager = $this->getServiceLocator()->get(EventManager::CONFIG_ID);
        $eventManager->attach($event, $callback);
        $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
    }
1240346
public function beforeFind(Event $event)
    {
        $related = $this->_getRelatedModels();
        if ($related === []) {
            $this->associations = [];
        } else {
            $this->associations = $this->_associations(array_keys($related));
        }

        if (!$event->getSubject()->query->getContain()) {
            $event->getSubject()->query->contain($related);
        }
    }
646709
public function handle(EventInterface $event)
    {
        $dir = yii::getAlias('@runtime');

        FileHelper::createDirectory($dir);
        file_put_contents($dir . DIRECTORY_SEPARATOR . 'events.log', $this->serializeEvent($event) . PHP_EOL, FILE_APPEND | LOCK_EX);
    }
122841
public function beforeFilter(Event $event)
    {
        $this->controller = $event->getSubject();
        $this->request = $this->controller->request;
        $this->action = $this->request->getParam('action');
        $this->Filters = TableRegistry::get($this->getConfig('filterTable'));

        $this->_setupSort();
        $this->_setupFilters();
        $this->_setupPagination();
    }
1124974
public function registerClientScript()
    {
        $selector = '#' . $this->htmlOptions['id'];
        Yii::app()->clientScript->registerScript(__CLASS__ . $selector, "jQuery('{$selector}').tab('show');");
        $this->registerEvents($selector, $this->events);
    }
804075
protected function handle(Event $event)
    {
        $method = $this->getApplyMethod($event);
        if (!method_exists($this, $method)) {
            return;
        }
        $this->$method($event);
    }
381785
public function beforeFilter(Event $event)
    {
        $this->viewBuilder()->className(Configure::read('CA.viewClass'))->theme(Configure::read('CA.theme'));

        if ($this->authUser) {
            $this->viewBuilder()->layout(Configure::read('CA.layout.default'));
        } else {
            $this->viewBuilder()->layout(Configure::read('CA.layout.login'));
        }

        $this->_addNotificationMenu();

        $event = new Event('CakeAdmin.Controller.beforeFilter', $this);
        EventManager::instance()->dispatch($event);
    }
918334
public function beforeRender(Event $event) {
		if (in_array('Captcha.Captcha', $this->controller->helpers) || isset($this->controller->helpers['Captcha.Captcha'])) {
			return;
		}

		$this->controller->helpers[] = 'Captcha.Captcha';
	}
628337
public function initialize(Event $event) {
		$table = $event->getSubject();
		if (!in_array(get_class($table), $this->config['tableClass'])) {
			return;
		}

		$this->_setValidators($table);
	}
277623
protected function handleError($event)
    {
        if (error_reporting() & $event->code) {
            $this->getSentryClient()->captureException(
                $this->createErrorException($event->message, $event->code, $event->file, $event->line)
            );
        }
        parent::handleError($event);
    }
741044
public function beforeSave($event)
    {
        list($id, $attribute) = $event->data;
        if (isset(self::$_executed[$id])) {
            return;
        }
        /* @var $object \yii\db\ActiveRecord */
        $object = $event->sender;
        if (is_string($this->format) && method_exists($object, $this->format)) {
            $value = call_user_func([$object, $this->format], $object, $attribute);
        } else {
            $value = is_callable($this->format) ? call_user_func($this->format, $object, $attribute) : $this->format;
        }
        $group = md5(serialize([
            'class' => $this->unique ? get_class($object) : false,
            'group' => $this->group,
            'attribute' => $attribute,
            'value' => $value
        ]));
        $model = Autonumber::findOne($group);
        if ($model) {
            $number = $model->number + 1;
        } else {
            $model = new Autonumber([
                'group' => $group
            ]);
            $number = 1;
        }
        $model->update_time = time();
        $model->number = $number;
        if ($value === null) {
            $object->$attribute = $number;
        } else {
            $object->$attribute = str_replace('?', $this->digit ? sprintf("%0{$this->digit}d", $number) : $number, $value);
        }
        self::$_executed[$id] = true;
        try {
            $model->save(false);
        } catch (\Exception $exc) {
            $event->isValid = false;
            if ($this->throwIsStale || !($exc instanceof StaleObjectException)) {
                throw $exc;
            }
        }
    }
776725
public function beforePrepare(Event $event)
	{
		$operation = $event['command']->getOperation();
		$client = $event['command']->getClient();

		if ($operation->hasParam('collection') === false) return;
		if (is_null($client->getCollectionName())) return;

		$operation->getParam('collection')->setDefault($client->getCollectionName());
		$operation->getParam('collection')->setStatic(true);

	}