/** * Test all empty values are mapped correctly. * * See https://github.com/MetaModels/attribute_file/issues/45#issuecomment-85937268 * * @return void */ public function testConvertUuidsOrPathsToMetaModelsEmpty() { $emptyExpected = array('bin' => array(), 'value' => array(), 'path' => array()); $this->assertEquals($emptyExpected, ToolboxFile::convertUuidsOrPathsToMetaModels(null)); $this->assertEquals($emptyExpected, ToolboxFile::convertUuidsOrPathsToMetaModels(array())); $this->assertEquals($emptyExpected, ToolboxFile::convertUuidsOrPathsToMetaModels(array(null))); }
/** * Get a 16x16 pixel resized icon of the passed image if it exists, return the default icon otherwise. * * @param string $icon The icon to resize. * * @param string $defaultIcon The default icon. * * @return string */ public function getBackendIcon($icon, $defaultIcon = 'system/modules/metamodels/assets/images/icons/metamodels.png') { $dispatcher = $this->getDispatcher(); $realIcon = ToolboxFile::convertValueToPath($icon); // Determine image to use. if ($realIcon && file_exists(TL_ROOT . '/' . $realIcon)) { $event = new ResizeImageEvent($realIcon, 16, 16); $dispatcher->dispatch(ContaoEvents::IMAGE_RESIZE, $event); return $event->getResultImage(); } return $defaultIcon; }
/** * {@inheritDoc} */ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSettings) { parent::prepareTemplate($objTemplate, $arrRowData, $objSettings); $objToolbox = new ToolboxFile(); $objToolbox->setBaseLanguage($this->getMetaModel()->getActiveLanguage()); $objToolbox->setFallbackLanguage($this->getMetaModel()->getFallbackLanguage()); $objToolbox->setLightboxId(sprintf('%s.%s.%s', $this->getMetaModel()->getTableName(), $objSettings->get('id'), $arrRowData['id'])); if (strlen($this->get('file_validFileTypes'))) { $objToolbox->setAcceptedExtensions($this->get('file_validFileTypes')); } $objToolbox->setShowImages($objSettings->get('file_showImage')); if ($objSettings->get('file_imageSize')) { $objToolbox->setResizeImages($objSettings->get('file_imageSize')); } if ($arrRowData[$this->getColName()]) { $value = $arrRowData[$this->getColName()]; if (isset($value['value'])) { foreach ($value['value'] as $strFile) { $objToolbox->addPathById($strFile); } } elseif (is_array($value)) { foreach ($value as $strFile) { $objToolbox->addPathById($strFile); } } else { $objToolbox->addPathById($value); } } $objToolbox->resolveFiles(); $arrData = $objToolbox->sortFiles($objSettings->get('file_sortBy')); $objTemplate->files = $arrData['files']; $objTemplate->src = $arrData['source']; }
/** * {@inheritDoc} */ public function getTranslatedDataFor($arrIds, $strLangCode) { $arrValues = parent::getTranslatedDataFor($arrIds, $strLangCode); foreach ($arrValues as $intId => $arrValue) { $arrValues[$intId]['value'] = ToolboxFile::convertUuidsOrPathsToMetaModels(deserialize($arrValue['value'], true)); } return $arrValues; }
/** * Handle stand alone integration in the backend. * * @param IInputScreen $inputScreen The input screen containing the information. * * @return void */ private function addModuleToBackendMenu($inputScreen) { $metaModel = $inputScreen->getMetaModel(); $moduleName = 'metamodel_' . $metaModel->getTableName(); $tableCaption = $metaModel->getName(); $icon = $this->buildIcon(ToolboxFile::convertValueToPath($inputScreen->getIcon())); $section = $inputScreen->getBackendSection(); if (!$section) { $section = 'metamodels'; } $this->backendMenu[$section][$moduleName] = array('tables' => array($metaModel->getTableName()), 'icon' => $icon, 'callback' => 'MetaModels\\BackendIntegration\\Module'); $caption = array($tableCaption); foreach ($inputScreen->getBackendCaption() as $languageEntry) { if ($languageEntry['langcode'] == 'en') { $caption = array($languageEntry['label'], $languageEntry['description']); } if (!empty($languageEntry['label']) && $languageEntry['langcode'] == $this->viewCombinations->getUser()->language) { $caption = array($languageEntry['label'], $languageEntry['description']); break; } } $this->languageStrings['MOD'][$moduleName] = $caption; }
/** * Test whether the given image exists. * * @param string $uuidImage The uuid of the image. * @param string $strDefault Path to the fallback image. * * @return string If the image exists, the image is returned, the default otherwise. */ protected function ensureImage($uuidImage, $strDefault) { $imagePath = ToolboxFile::convertValueToPath($uuidImage); if (strlen($imagePath) && file_exists(TL_ROOT . '/' . $imagePath)) { return $imagePath; } return $strDefault; }
/** * Generate a 16x16 pixel version of the passed image file. If this can not be done, the default image is returned. * * @param string $icon The name of the image file. * * @return null|string */ public function getBackendIcon($icon) { // Determine the image to use. if ($icon) { $icon = ToolboxFile::convertValueToPath($icon); /** @var ResizeImageEvent $event */ $event = $this->serviceContainer->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_RESIZE, new ResizeImageEvent($icon, 16, 16)); if (file_exists(TL_ROOT . '/' . $event->getResultImage())) { return $event->getResultImage(); } } return 'system/modules/metamodels/assets/images/icons/metamodels.png'; }