/**
  * {@inheritdoc}
  */
 protected function delete($object)
 {
     $result = $this->blockManager->set($object)->delete();
     return $result;
 }
Example #2
0
 public function generateFromBlockDefinition($blockDefinition, BlockManagerInterface $blockManager, array $values)
 {
     $default = $blockManager->getDefaultValue();
     $blockDefinitionDecoded = json_decode($blockDefinition, true);
     $nextItems = null;
     if (array_key_exists("items", $blockDefinitionDecoded)) {
         $nextItems = $blockDefinitionDecoded["items"];
         $items = array();
         foreach ($nextItems as $nextItem) {
             $items[] = array_intersect_key($nextItem, array('blockType' => ''));
         }
         $blockDefinitionDecoded["items"] = $items;
     }
     if (array_key_exists("blockType", $blockDefinitionDecoded)) {
         unset($blockDefinitionDecoded["blockType"]);
     }
     $defaultValue = json_decode($default["Content"], true);
     if (!is_array($defaultValue)) {
         return true;
     }
     $values["Content"] = json_encode(array_replace_recursive($defaultValue, $blockDefinitionDecoded));
     $blockManager->set(null);
     if (!$blockManager->save($values)) {
         return false;
     }
     if (null !== $nextItems) {
         $i = 0;
         $blockId = $blockManager->get()->getId();
         foreach ($nextItems as $nextItem) {
             $values["SlotName"] = $blockId . '-' . $i;
             $values["Type"] = $nextItem["blockType"];
             $blockManager = $this->blockManagerFactory->createBlockManager($nextItem["blockType"]);
             if (!$this->generateFromBlockDefinition(json_encode($nextItem), $blockManager, $values)) {
                 return false;
             }
             $i++;
         }
     }
     return true;
 }