Create a new singles list and replace the old one with it

@param RegisterElementSourcesEvent $event

@return void
340616
public function createSinglesList(RegisterElementSourcesEvent $event)
    {
        $singles[] = ['heading' => Craft::t('app', 'Singles')];

        // Grab all the Singles
        $singleSections = Craft::$app->sections->getSectionsByType(Section::TYPE_SINGLE);

        // Create list of Singles
        foreach ($singleSections as $single) {
            $entry = null;
            
            // If this is a multi-site, we need to grab the first site-enabled entry
            // Kind of annoying we can't query multiple site ids, or _all_ sites
            // https://github.com/craftcms/cms/issues/2854
            if (Craft::$app->getIsMultiSite()) {
                foreach (Craft::$app->getSites()->getAllSiteIds() as $key => $siteId) {
                    $entry = Entry::find()
                        ->siteId($siteId)
                        ->status(null)
                        ->sectionId($single->id)
                        ->one();

                    if ($entry) {
                        break;
                    }
                }
            } else {
                $entry = Entry::find()
                    ->status(null)
                    ->sectionId($single->id)
                    ->one();
            }

            if ($entry && Craft::$app->getUser()->checkPermission('editEntries:' . $single->uid)) {
                $url = $entry->getCpEditUrl();

                $singles[] = [
                    'key' => 'single:' . $single->uid,
                    'label' => Craft::t('site', $single->name),
                    'sites' => $single->getSiteIds(),
                    'data' => [
                        'url' => $url,
                        'handle' => $single->handle
                    ],
                    'criteria' => [
                        'sectionId' => $single->id,
                        'editable' => false,
                    ]
                ];
            }
        }

        // Replace original Singles link with new singles list
        array_splice($event->sources, 1, 1, $singles);

        // Insert some JS to go straight to single page when clicked - rather than listing in Index Table
        if (ExpandedSingles::$plugin->getSettings()->redirectToEntry) {
            $js = '$(function() {' .
                '$("#main-content #sidebar nav a[data-url]").each(function(i, e) {' .
                    'var link = "<a href=" + $(this).data("url") + ">" + $(this).text() + "</a>";' .
                        '$(this).replaceWith($(link));' .
                    '});' .
                '});';

            Craft::$app->view->registerJs($js);
        }

        // Update our element indexes to use the same columns as the original singles items
        // $newSettings = [];
        // $settings = Craft::$app->getElementIndexes()->getSettings(Entry::class);

        // // Get the singles index info - if none exists, then no need to go further
        // $singlesSettings = $settings['sources']['singles'] ?? null;

        // if (!$singlesSettings) {
        //     return;
        // }

        // foreach ($singles as $key => $single) {
        //     if (isset($single['key'])) {
        //         $newSettings[$single['key']] = $singlesSettings;
        //     }
        // }

        // Craft::$app->getElementIndexes()->saveSettings(Entry::class, $newSettings);
    }
604680
public function triggerEvent(string $event): void
    {
        // TODO: use event library and allow attach events to IFile and ICacheStateful.
        // cache triggers
        if ($this->file instanceof ICacheStateful) {
            switch ($event) {
                case self::EVENT_CACHED:
                    $this->file->setCachedAt($this->name, time());
                    break;
                case self::EVENT_EMPTY:
                case self::EVENT_ERROR:
                case self::EVENT_NOT_FOUND:
                    // TODO: split those and save different cases of cache state.
                    $this->file->setCachedAt($this->name, null);
                    break;
            }

            $this->file->saveState();
        }

        // other triggers
    }
727557
public function beforeInsert($event)
    {
        foreach ($this->insert as $field) {
            $event->sender->$field = time();
        }
    }
83676
public function onDelete(DeleteResourceEvent $event)
    {
        $ds = DIRECTORY_SEPARATOR;

        /** @var File $resource */
        $resource = $event->getResource();
        $workspace = $resource->getResourceNode()->getWorkspace();
        $hashName = $resource->getHashName();

        $archiveFile = $this->filesDir.$ds.'webresource'.$ds.$workspace->getUuid().$ds.$hashName;
        $webResourcesPath = $this->uploadDir.$ds.'webresource'.$ds.$workspace->getUuid().$ds.$hashName;

        if (file_exists($archiveFile)) {
            $event->setFiles([$archiveFile]);
        }
        if (file_exists($webResourcesPath)) {
            try {
                $this->deleteFiles($webResourcesPath);
            } catch (\Exception $e) {
            }
        }
        $this->om->remove($resource);
        $event->stopPropagation();
    }
1366361
public static function registerPackage(Event $event)
    {
        $installedPackage = $event->getOperation()->getPackage();

        if (!self::isBundle($installedPackage)) {
            return;
        }

        self::enablePackage($installedPackage);
    }
1274844
public function registerEvents($events)
    {
        if (empty($events)) {
            throw new \RuntimeException(sprintf('Empty argument passed %s', __FUNCTION__));
        }

        foreach ($events as $event => $namespace) {
            $parts = explode('@', $namespace);
            // attach all before and after event to handler
            $this->register("$event.before", $parts[0].'@before'.ucfirst(Inflector::pathAction(end($parts))))
                 ->register("$event", $parts[0].'@'.Inflector::pathAction(end($parts)))
                 ->register("$event.after", $parts[0].'@after'.ucfirst(Inflector::pathAction(end($parts))));
        }
    }
173117
public static function run(Event $event)
    {
        $event->getIO()->write('<info>Now running setup tasks...</info>');
        $config = static::getConfig($event);
        $tasks  = static::getSetupTasks($event);
        foreach ($tasks as $task) {
            /** @var SetupTask $taskStep */
            $taskStep = new $task($config, $event);
            $event->getIO()->write(
                sprintf(
                    '<info>Task %1$s</info>',
                    $taskStep->getName()
                )
            );
            $taskStep->complete();
        }
        $event->getIO()->write('<info>Setup tasks complete, cleaning up...</info>');
    }
52200
public function load(LoadResourceEvent $event)
    {
        /** @var Shortcut $shortcut */
        $shortcut = $event->getResource();

        $this->resourceLifecycle->load($shortcut->getTarget());
    }
55217
public static function register($event, $callback)
	{
		// make sure we're setting the correct events
		$event = str_replace(array('before', 'after', 'validate'), array('before_save', 'after_save', 'after_validation'), $event);

		static::$upload->register($event, $callback);
	}
655913
public function onCreate(CreateResourceEvent $event)
    {
        $request = $this->container->get('request');
        $form = $this->formFactory->create(new DirectoryType(), new Directory());
        $form->handleRequest($request);

        if ($form->isValid()) {
            $published = $form->get('published')->getData();
            $event->setPublished($published);
            $event->setResources(array($form->getData()));
            $event->stopPropagation();

            return;
        }

        $content = $this->templating->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'directory'
            )
        );
        $event->setErrorFormContent($content);
        $event->stopPropagation();
    }
1017453
public function onAfterInitialise(Event $event): void
    {
        /** @var WebApplication $app */
        $app = $event['app'];

        // Remove index.php
        if ($app->uri->script === 'index.php') {
            $app->uri->script = null;
        }
    }
731411
public function onLoad(LoadResourceEvent $event)
    {
        /** @var File $resource */
        $resource = $event->getResource();
        $path = $this->filesDir.DIRECTORY_SEPARATOR.$resource->getHashName();

        $additionalFileData = [];

        /** @var LoadFileEvent $loadEvent */
        $loadEvent = $this->eventDispatcher->dispatch(
            $this->generateEventName($resource->getResourceNode(), 'load'),
            LoadFileEvent::class,
            [$resource, $path]
        );

        if ($event->isPopulated()) {
            $additionalFileData = $loadEvent->getData();
        } else {
            // no listener found, try to dispatch the fallback event
            /** @var LoadFileEvent $fallBackEvent */
            $fallBackEvent = $this->eventDispatcher->dispatch(
                $this->generateEventName($resource->getResourceNode(), 'load', true),
                LoadFileEvent::class,
                [$resource, $path]
            );

            if ($fallBackEvent->isPopulated()) {
                $additionalFileData = $fallBackEvent->getData();
            }
        }

        $event->setData([
            // common file data
            'file' => array_merge(
                $additionalFileData,
                // standard props are in 2nd to make sure custom file serializer doesn't override them
                $this->serializer->serialize($resource)
            ),
        ]);
    }
992524
public function onNewCodeEvent(Event $event)
    {
        $vendorDir   = $event->getComposer()->getConfig()->get('vendor-dir');
        $projectDir  = dirname($vendorDir);
        $phpStormDir = $projectDir . DIRECTORY_SEPARATOR . '.idea';
        $filesDir    = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'files';

        if (is_dir($phpStormDir) && is_dir($filesDir)) {
            $this->patcher->patch(
                new Environment(
                    new Filesystem($phpStormDir),
                    new Filesystem($filesDir),
                    new Filesystem($projectDir),
                    $event->getIO(),
                    $event->getComposer()
                )
            );

            $output = $event->getIO();
            if ($output->isVerbose()) {
                $output->write('Patched the PhpStorm config');
            }
        }
    }
1232031
public function createVersions(Event $Event) {
		if ($this->_checkEvent($Event)) {
			$table = $Event->getSubject();
			$record = $Event->getData('record');
			$this->_createVersions($table, $record, $Event->getData('operations'));
			$Event->stopPropagation();
		}
	}
105002
public function onCreate(CreateResourceEvent $event)
    {
        $form = $this->container->get('form.factory')->create(DropzoneType::class, new Dropzone());
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $dropzone = $form->getData();
            $event->setResources([$dropzone]);
        } else {
            $content = $this->container->get('templating')->render(
                'ClarolineCoreBundle:resource:create_form.html.twig',
                [
                    'form' => $form->createView(),
                    'resourceType' => 'icap_dropzone',
                ]
            );
            $event->setErrorFormContent($content);
        }
        $event->stopPropagation();
    }
317151
public function load(LoadResourceEvent $event)
    {
        $resourceNode = $event->getResourceNode();

        /** @var Wiki $wiki */
        $wiki = $event->getResource();
        $sectionTree = $this->sectionManager->getSerializedSectionTree(
            $wiki,
            $this->tokenStorage->getToken()->getUser() instanceof User ? $this->tokenStorage->getToken()->getUser() : null,
            $this->checkPermission('EDIT', $resourceNode)
        );

        $event->setData([
            'wiki' => $this->serializer->serialize($wiki),
            'sections' => $sectionTree,
        ]);

        $event->stopPropagation();
    }
303896
public function addEvent(IDS_Event $event)
    {
        $this->clear();
        $this->events[$event->getName()] = $event;

        return $this;
    }