/** * Hydrate the update form for this object, before passing it to the update template * * @param Sale $sale * @return SaleModificationForm */ protected function hydrateObjectForm($sale) { // Find all categories of the selected products $saleProducts = $sale->getSaleProductList(); $categories = $products = []; /** @var SaleProduct $saleProduct */ foreach ($saleProducts as $saleProduct) { $categories[] = $saleProduct->getProduct()->getDefaultCategoryId(); $products[] = $saleProduct->getProduct()->getId(); } $dateFormat = SaleModificationForm::PHP_DATE_FORMAT; // Transform the selected attributes list (product_id => array of attributes av id) into // product_id => comma separated list of attributes av id, to math the collection type (text) $saleProductsAttributesAvs = $sale->getSaleProductsAttributeList(); $product_attributes = []; foreach ($saleProductsAttributesAvs as $productId => $saleProductsAttributesAv) { $product_attributes[$productId] = implode(',', $saleProductsAttributesAv); } // Prepare the data that will hydrate the form $data = ['id' => $sale->getId(), 'locale' => $sale->getLocale(), 'title' => $sale->getTitle(), 'label' => $sale->getSaleLabel(), 'chapo' => $sale->getChapo(), 'description' => $sale->getDescription(), 'postscriptum' => $sale->getPostscriptum(), 'active' => $sale->getActive(), 'display_initial_price' => $sale->getDisplayInitialPrice(), 'start_date' => $sale->getStartDate($dateFormat), 'end_date' => $sale->getEndDate($dateFormat), 'price_offset_type' => $sale->getPriceOffsetType(), 'price_offset' => $sale->getPriceOffsets(), 'categories' => $categories, 'products' => $products, 'product_attributes' => $product_attributes]; // Setup the object form return new SaleModificationForm($this->getRequest(), "form", $data); }