Pimcore\Model\Object\Service::synchronizeCustomLayout PHP Method

synchronizeCustomLayout() public static method

Synchronizes a custom layout with its master layout
public static synchronizeCustomLayout ( CustomLayout $customLayout )
$customLayout Pimcore\Model\Object\ClassDefinition\CustomLayout
    public static function synchronizeCustomLayout(ClassDefinition\CustomLayout $customLayout)
    {
        $classId = $customLayout->getClassId();
        $class = ClassDefinition::getById($classId);
        if ($class && $class->getModificationDate() > $customLayout->getModificationDate()) {
            $masterDefinition = $class->getFieldDefinitions();
            $customLayoutDefinition = $customLayout->getLayoutDefinitions();
            $targetList = self::extractLocalizedFieldDefinitions($class->getLayoutDefinitions(), [], false);
            $masterDefinition = array_merge($masterDefinition, $targetList);
            self::synchronizeCustomLayoutFieldWithMaster($masterDefinition, $customLayoutDefinition);
            $customLayout->save();
        }
    }

Usage Example

Example #1
0
 /**
  * @param $id
  * @return mixed|null|CustomLayout
  * @throws \Exception
  */
 public static function getById($id)
 {
     if ($id === null) {
         throw new \Exception("CustomLayout id is null");
     }
     $cacheKey = "customlayout_" . $id;
     try {
         $customLayout = \Zend_Registry::get($cacheKey);
         if (!$customLayout) {
             throw new \Exception("Custom Layout in registry is null");
         }
     } catch (\Exception $e) {
         try {
             $customLayout = new self();
             $customLayout->getDao()->getById($id);
             Object\Service::synchronizeCustomLayout($customLayout);
             \Zend_Registry::set($cacheKey, $customLayout);
         } catch (\Exception $e) {
             \Logger::error($e);
             return null;
         }
     }
     return $customLayout;
 }