本文整理匯總了PHP中Magento\Framework\View\Design\ThemeInterface類的典型用法代碼示例。如果您正苦於以下問題:PHP ThemeInterface類的具體用法?PHP ThemeInterface怎麽用?PHP ThemeInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ThemeInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getFiles
/**
* Retrieve files
*
* @param ThemeInterface $theme
* @param string $filePath
* @return array|\Magento\Framework\View\File[]
* @throws \Magento\Framework\Exception
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$namespace = $module = '*';
$themePath = $theme->getFullPath();
$searchPattern = "{$themePath}/{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}";
$files = $this->themesDirectory->search($searchPattern);
if (empty($files)) {
return [];
}
$themes = [];
$currentTheme = $theme;
while ($currentTheme = $currentTheme->getParentTheme()) {
$themes[$currentTheme->getCode()] = $currentTheme;
}
$result = [];
$pattern = "#/(?<module>[^/]+)/{$this->subDir}(?<themeVendor>[^/]+)/(?<themeName>[^/]+)/" . strtr(preg_quote($filePath), ['\\*' => '[^/]+']) . "\$#i";
foreach ($files as $file) {
$filename = $this->themesDirectory->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$moduleFull = $matches['module'];
$ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName'];
if (!isset($themes[$ancestorThemeCode])) {
throw new Exception(sprintf("Trying to override modular view file '%s' for theme '%s', which is not ancestor of theme '%s'", $filename, $ancestorThemeCode, $theme->getCode()));
}
$result[] = $this->fileFactory->create($filename, $moduleFull, $themes[$ancestorThemeCode]);
}
return $result;
}
示例2: getFiles
/**
* Retrieve files
*
* @param ThemeInterface $theme
* @param string $filePath
* @return \Magento\Framework\View\File[]
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$namespace = $module = '*';
$themePath = $theme->getFullPath();
if (empty($themePath)) {
return [];
}
$themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
if (!$themeAbsolutePath) {
return [];
}
$themeDir = $this->readDirFactory->create($themeAbsolutePath);
$searchPattern = "{$namespace}_{$module}/{$this->subDir}{$filePath}";
$files = $themeDir->search($searchPattern);
$result = [];
$pattern = "#(?<moduleName>[^/]+)/{$this->subDir}" . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "\$#i";
foreach ($files as $file) {
$filename = $themeDir->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$result[] = $this->fileFactory->create($filename, $matches['moduleName']);
}
return $result;
}
示例3: getFiles
/**
* Retrieve files
*
* @param ThemeInterface $theme
* @param string $filePath
* @return array|\Magento\Framework\View\File[]
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$result = [];
$namespace = $module = '*';
$sharedFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/base/{$this->subDir}{$filePath}");
$filePathPtn = strtr(preg_quote($filePath), ['\\*' => '[^/]+']);
$pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/base/{$this->subDir}" . $filePathPtn . "\$#i";
foreach ($sharedFiles as $file) {
$filename = $this->modulesDirectory->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$moduleFull = "{$matches['namespace']}_{$matches['module']}";
$result[] = $this->fileFactory->create($filename, $moduleFull, null, true);
}
$area = $theme->getData('area');
$themeFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/{$area}/{$this->subDir}{$filePath}");
$pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/{$area}/{$this->subDir}" . $filePathPtn . "\$#i";
foreach ($themeFiles as $file) {
$filename = $this->modulesDirectory->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$moduleFull = "{$matches['namespace']}_{$matches['module']}";
$result[] = $this->fileFactory->create($filename, $moduleFull);
}
return $result;
}
示例4: create
/**
* Create new config object
*
* @param ThemeInterface $theme
* @return mixed
* @throws \Magento\Framework\Exception
*/
public function create(ThemeInterface $theme)
{
if (!isset($this->_types[$theme->getType()])) {
throw new \Magento\Framework\Exception(sprintf('Invalid type of theme domain model "%s"', $theme->getType()));
}
$class = $this->_types[$theme->getType()];
return $this->_objectManager->create($class, ['theme' => $theme]);
}
示例5: testToHtmlPreviewImageUrl
public function testToHtmlPreviewImageUrl()
{
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$this->_theme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL);
$this->_theme->setPreviewImage('preview_image_test.jpg');
$this->_block->setArea('adminhtml');
$html = $this->_block->toHtml();
preg_match_all('/pub\\/static\\/adminhtml\\/_view\\/en_US/', $html, $result);
$this->assertEmpty($result[0]);
}
示例6: __construct
/**
* @param \Magento\Framework\View\DesignInterface $design
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\Event\ManagerInterface $eventDispatcher
* @param \Magento\Framework\View\ConfigInterface $viewConfig
* @param \Magento\DesignEditor\Model\Config\Control\AbstractControl $configuration
* @param \Magento\Framework\View\Design\ThemeInterface $theme
* @param \Magento\Framework\View\Design\ThemeInterface $parentTheme
*/
public function __construct(\Magento\Framework\View\DesignInterface $design, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Event\ManagerInterface $eventDispatcher, \Magento\Framework\View\ConfigInterface $viewConfig, \Magento\DesignEditor\Model\Config\Control\AbstractControl $configuration = null, \Magento\Framework\View\Design\ThemeInterface $theme = null, \Magento\Framework\View\Design\ThemeInterface $parentTheme = null)
{
$this->_configuration = $configuration;
$this->_theme = $theme;
$this->_parentTheme = $parentTheme ?: $theme->getParentTheme();
$this->_design = $design;
$this->_filesystem = $filesystem;
$this->_eventDispatcher = $eventDispatcher;
$this->_viewConfigLoader = $viewConfig;
$this->_initViewConfigs()->_loadControlsData();
}
示例7: getFiles
/**
* Retrieve files
*
* @param ThemeInterface $theme
* @param string $filePath
* @return array|\Magento\Framework\View\File[]
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$themePath = $theme->getFullPath();
$files = $this->themesDirectory->search("{$themePath}/{$this->subDir}{$filePath}");
$result = [];
foreach ($files as $file) {
$filename = $this->themesDirectory->getAbsolutePath($file);
$result[] = $this->fileFactory->create($filename, null, $theme);
}
return $result;
}
示例8: fetchUpdatesByHandle
/**
* Retrieve layout updates by handle
*
* @param string $handle
* @param \Magento\Framework\View\Design\ThemeInterface $theme
* @param \Magento\Framework\App\ScopeInterface $store
* @return string
*/
public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Framework\App\ScopeInterface $store)
{
$bind = ['layout_update_handle' => $handle, 'theme_id' => $theme->getId(), 'store_id' => $store->getId()];
$result = '';
$connection = $this->getConnection();
if ($connection) {
$select = $this->_getFetchUpdatesByHandleSelect();
$result = join('', $connection->fetchCol($select, $bind));
}
return $result;
}
示例9: setup
public function setup()
{
$this->themeDirectoryMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock();
$this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\File\\Factory')->disableOriginalConstructor()->getMock();
$this->themeMock = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMock();
$this->themeMock->expects($this->once())->method('getFullPath')->will($this->returnValue($this->themePath));
$this->readDirFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false);
$this->readDirFactory->expects($this->any())->method('create')->will($this->returnValue($this->themeDirectoryMock));
$this->componentRegistrar = $this->getMockForAbstractClass('Magento\\Framework\\Component\\ComponentRegistrarInterface');
$this->themeFileCollector = new Theme($this->fileFactoryMock, $this->readDirFactory, $this->componentRegistrar);
}
示例10: getFiles
/**
* Retrieve files
*
* @param \Magento\Framework\View\Design\ThemeInterface $theme
* @param string $filePath
* @return \Magento\Framework\View\File[]
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$result = [];
$sharedFiles = $this->componentDirSearch->collectFilesWithContext(ComponentRegistrar::MODULE, "view/base/{$this->subDir}{$filePath}");
foreach ($sharedFiles as $file) {
$result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName(), null, true);
}
$area = $theme->getData('area');
$themeFiles = $this->componentDirSearch->collectFilesWithContext(ComponentRegistrar::MODULE, "view/{$area}/{$this->subDir}{$filePath}");
foreach ($themeFiles as $file) {
$result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName());
}
return $result;
}
示例11: fetchUpdatesByHandle
/**
* Retrieve layout updates by handle
*
* @param string $handle
* @param \Magento\Framework\View\Design\ThemeInterface $theme
* @param \Magento\Framework\App\ScopeInterface $store
* @return string
*/
public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Framework\App\ScopeInterface $store)
{
$bind = ['theme_id' => $theme->getId(), 'store_id' => $store->getId()];
$cacheKey = implode('-', $bind);
if (!isset($this->layoutUpdateCache[$cacheKey])) {
$this->layoutUpdateCache[$cacheKey] = [];
foreach ($this->getConnection()->fetchAll($this->_getFetchUpdatesByHandleSelect(), $bind) as $layout) {
if (!isset($this->layoutUpdateCache[$cacheKey][$layout['handle']])) {
$this->layoutUpdateCache[$cacheKey][$layout['handle']] = '';
}
$this->layoutUpdateCache[$cacheKey][$layout['handle']] .= $layout['xml'];
}
}
return isset($this->layoutUpdateCache[$cacheKey][$handle]) ? $this->layoutUpdateCache[$cacheKey][$handle] : '';
}
示例12: _createStagingTheme
/**
* Create 'staging' theme associated with current 'virtual' theme
*
* @return \Magento\Framework\View\Design\ThemeInterface
*/
protected function _createStagingTheme()
{
$stagingTheme = $this->_themeFactory->create();
$stagingTheme->setData(['parent_id' => $this->_theme->getId(), 'theme_path' => null, 'theme_title' => sprintf('%s - Staging', $this->_theme->getThemeTitle()), 'preview_image' => $this->_theme->getPreviewImage(), 'is_featured' => $this->_theme->getIsFeatured(), 'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_STAGING]);
$stagingTheme->save();
return $stagingTheme;
}
示例13: update
/**
* Creates or updates custom single file which belong to a selected theme
*
* @param \Magento\Framework\View\Design\ThemeInterface $themeModel
* @param string $fileContent
* @return \Magento\Framework\View\Design\Theme\FileInterface
*/
public function update(\Magento\Framework\View\Design\ThemeInterface $themeModel, $fileContent)
{
$customFiles = $themeModel->getCustomization()->getFilesByType($this->_fileService->getType());
$customCss = reset($customFiles);
if (empty($fileContent) && $customCss) {
$customCss->delete();
return $customCss;
}
if (!$customCss) {
$customCss = $this->_fileService->create();
}
$customCss->setData('content', $fileContent);
$customCss->setTheme($themeModel);
$customCss->save();
return $customCss;
}
示例14: _addThemeFieldset
/**
* Add theme fieldset
*
* @param \Magento\Framework\Data\Form $form
* @param array $formData
* @param ThemeInterface $theme
* @return $this
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _addThemeFieldset($form, $formData, ThemeInterface $theme)
{
$themeFieldset = $form->addFieldset('theme', ['legend' => __('Theme Settings')]);
$this->_addElementTypes($themeFieldset);
if (isset($formData['theme_id'])) {
$themeFieldset->addField('theme_id', 'hidden', ['name' => 'theme_id']);
}
/** @var \Magento\Theme\Model\Theme\Collection $themesCollections */
$themesCollections = $this->_objectManager->create('Magento\\Theme\\Model\\Theme\\Collection');
/** @var \Magento\Framework\Json\Helper\Data $helper */
$helper = $this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data');
$onChangeScript = sprintf('parentThemeOnChange(this.value, %s)', str_replace('"', '\'', $helper->jsonEncode($this->_getDefaultsInherited($themesCollections->addDefaultPattern()))));
/** @var ThemeInterface $parentTheme */
$parentTheme = $this->_objectManager->create('Magento\\Framework\\View\\Design\\ThemeInterface');
if (!empty($formData['parent_id'])) {
$parentTheme->load($formData['parent_id']);
}
if ($this->_getCurrentTheme()->isObjectNew()) {
$themeFieldset->addField('parent_id', 'select', ['label' => __('Parent Theme'), 'title' => __('Parent Theme'), 'name' => 'parent_id', 'values' => $themesCollections->toOptionArray(!$parentTheme->getId()), 'required' => true, 'class' => 'no-changes', 'onchange' => $onChangeScript]);
} elseif (!empty($formData['parent_id'])) {
$themeFieldset->addField('parent_title', 'note', ['label' => __('Parent Theme'), 'title' => __('Parent Theme'), 'name' => 'parent_title', 'text' => $parentTheme->getId() ? $parentTheme->getThemeTitle() : '']);
}
if (!empty($formData['theme_path'])) {
$themeFieldset->addField('theme_path', 'label', ['label' => __('Theme Path'), 'title' => __('Theme Path'), 'name' => 'theme_code']);
}
$themeFieldset->addField('theme_title', $this->_getFieldTextType(), ['label' => __('Theme Title'), 'title' => __('Theme Title'), 'name' => 'theme_title', 'required' => $this->_isFieldAttrRequired()]);
if ($this->_isThemeEditable) {
$themeFieldset->addField('preview_image', 'image', ['label' => __('Theme Preview Image'), 'title' => __('Theme Preview Image'), 'name' => 'preview', 'required' => false, 'note' => $this->_getPreviewImageNote(), 'theme' => $theme]);
} elseif ($theme->hasPreviewImage()) {
$themeFieldset->addField('preview_image', 'note', ['label' => __('Theme Preview Image'), 'title' => __('Theme Preview Image'), 'name' => 'preview', 'after_element_html' => '<a href="' . $theme->getThemeImage()->getPreviewImageUrl() . '" onclick="imagePreview(\'theme_preview_image\'); return false;">' . '<img width="50" src="' . $theme->getThemeImage()->getPreviewImageUrl() . '" id="theme_preview_image" /></a>']);
}
return $this;
}
示例15: assignToStore
/**
* Assign theme to the stores
*
* @param \Magento\Framework\View\Design\ThemeInterface $theme
* @param array $stores
* @param string $scope
* @return $this
*/
public function assignToStore($theme, array $stores = array(), $scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES)
{
$isReassigned = false;
$this->_unassignThemeFromStores($theme->getId(), $stores, $scope, $isReassigned);
if ($this->_storeManager->isSingleStoreMode()) {
$this->_assignThemeToDefaultScope($theme->getId(), $isReassigned);
} else {
$this->_assignThemeToStores($theme->getId(), $stores, $scope, $isReassigned);
}
if ($isReassigned) {
$this->_configCache->clean();
$this->_layoutCache->clean();
}
$this->_eventManager->dispatch('assign_theme_to_stores_after', array('stores' => $stores, 'scope' => $scope, 'theme' => $theme));
return $this;
}