getHookFileName(); } /** * Get PCI Creator hooks directly located at views/js/pciCreator/myCustomInteraction: * * @return array */ public function getDevImplementations() { $returnValue = []; $hookFileName = $this->getHookFileName(); foreach (glob($this->getBaseDevDir() . '*/' . $hookFileName . '.js') as $file) { $dir = str_replace($hookFileName . '.js', '', $file); $manifestFile = $dir . $hookFileName . '.json'; if (file_exists($manifestFile)) { $typeIdentifier = basename($dir); $baseUrl = $this->getBaseDevUrl() . $typeIdentifier . '/'; $manifest = json_decode(file_get_contents($manifestFile), true); $returnValue[] = [ 'typeIdentifier' => $typeIdentifier, 'label' => $manifest['label'], 'directory' => $dir, 'baseUrl' => $baseUrl, 'file' => $this->getEntryPointFile($typeIdentifier), 'manifest' => $manifest, 'dev' => true, 'debug' => (isset($manifest['debug']) && $manifest['debug']), 'registry' => get_class($this) ]; } } return $returnValue; } /** * Get PCI Creator hook located at views/js/{{hookFileName}}/$typeIdentifier * * @param string $typeIdentifier * @return array */ public function getDevImplementation($typeIdentifier) { //@todo : re-implement it to be more optimal $devImplementations = $this->getDevImplementations(); foreach ($devImplementations as $impl) { if ($impl['typeIdentifier'] == $typeIdentifier) { return $impl; } } return null; } /** * Get the path to the directory of a the Creator located at views/js/{{hookFileName}}/ * * @param string $typeIdentifier * @return string * @throws \common_Exception */ public function getDevImplementationDirectory($typeIdentifier) { $dir = $this->getBaseDevDir() . $typeIdentifier; if (file_exists($dir)) { return $dir; } else { throw new \common_Exception('the type identifier cannot be found'); } } /** * Get the data of the implementation by its typeIdentifier * * @param string $typeIdentifier * @return array */ protected function getImplementatioByTypeIdentifier($typeIdentifier) { return $this->getDevImplementation($typeIdentifier); } /** * Add required resources for a custom interaction (css, js) in the item directory * * @param string $typeIdentifier * @param \core_kernel_classes_Resource $item * @throws common_exception_Error */ public function addRequiredResources($typeIdentifier, core_kernel_classes_Resource $item) { //find the interaction in the registry $implementationData = $this->getImplementatioByTypeIdentifier($typeIdentifier); if (is_null($implementationData)) { throw new common_exception_Error('no implementation found with the type identifier ' . $typeIdentifier); } //get the root directory of the interaction $directory = $implementationData['directory']; //get the lists of all required resources $manifest = $implementationData['manifest']; $required = [$manifest['entryPoint']]; //include libraries remotely only, so this block is temporarily disabled foreach ($manifest['libraries'] as $lib) { if (!ClientLibRegistry::getRegistry()->isRegistered($lib)) { $lib = preg_replace('/^.\//', '', $lib); $lib .= '.js'; //add js extension $required[] = $lib; } } //include custom interaction specific css in the item if (isset($manifest['css'])) { $required = array_merge($required, array_values($manifest['css'])); } //include media in the item if (isset($manifest['media'])) { $required = array_merge($required, array_values($manifest['media'])); } //add them to the rdf item $resources = Authoring::addRequiredResources($directory, $required, $typeIdentifier, $item, ''); return $resources; } }