| @@ -133,3 +133,71 @@ function arlista_page_attachments(array &$attachments) { | |||
| $attachments['#attached']['drupalSettings']['arlista']['host'] = strtok($_SERVER["REQUEST_URI"], '?'); | |||
| $attachments['#attached']['drupalSettings']['arlista']['basePath'] = str_replace("/index.php", "", $_SERVER["PHP_SELF"]); | |||
| } | |||
| /** | |||
| * Reorder sheetsettings index by Munkalap Sorrend::field_sheet_setting_id order | |||
| */ | |||
| function arlista_entity_update(Drupal\Core\Entity\EntityInterface $entity) { | |||
| if(!$entity->hasField('field_sheet_settings')){ | |||
| return; | |||
| } | |||
| $nodes = $entity->get('field_sheet_settings')->referencedEntities(); | |||
| $sheetSettingFactory = $barista = \Drupal::getContainer()->get('arlista.sheet-setting.factory'); | |||
| $i = 0; | |||
| foreach($nodes as $sheetSettingNode){ | |||
| $sheetSetting = $sheetSettingFactory->find($sheetSettingNode->field_sheet_setting_id->value); | |||
| $sheetSetting->setIndex($i); | |||
| $sheetSettingFactory->save($sheetSetting); | |||
| $i++; | |||
| } | |||
| } | |||
| /** | |||
| * Add redirects for: | |||
| * - submit | |||
| * - cancel | |||
| * Hide buttons: | |||
| * - preview | |||
| * - delete | |||
| */ | |||
| function arlista_form_node_munkalap_sorrend_edit_form_alter( array &$form, Drupal\Core\Form\FormStateInterface $form_state, $form_id ) { | |||
| $form['#submit'][] = 'arlista_custom_node_submit_handler'; | |||
| $form['actions']['submit']['#submit'][] = 'arlista_custom_node_submit_handler'; | |||
| unset($form['actions']['preview']); | |||
| unset($form['actions']['delete']); | |||
| $form['actions']['cancel']['back'] = [ | |||
| '#type' => 'submit', | |||
| '#submit' => [ | |||
| 'arlista_custom_node_edit_cancel_handler', | |||
| ], | |||
| '#value' => 'Vissza a gyártóhoz', | |||
| '#limit_validation_errors' => [], | |||
| '#weight' => 910, | |||
| ]; | |||
| } | |||
| function arlista_custom_node_submit_handler($form, Drupal\Core\Form\FormStateInterface $form_state) { | |||
| $form_state->setRedirect('arlista.manufacturer.edit',array('mid' => $form_state->getFormObject()->getEntity()->get('field_manufacturer_id')->value)); | |||
| } | |||
| function arlista_custom_node_edit_cancel_handler($form, Drupal\Core\Form\FormStateInterface $form_state) { | |||
| $form_state->setRedirect('arlista.manufacturer.edit',array('mid' => $form_state->getFormObject()->getEntity()->get('field_manufacturer_id')->value)); | |||
| } | |||
| /** | |||
| * Hide tabs: | |||
| * - delete | |||
| * - history | |||
| * - view | |||
| */ | |||
| function arlista_menu_local_tasks_alter(&$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) { | |||
| //var_dump($data['tabs']); | |||
| unset($data['tabs'][0]['entity.node.canonical']); | |||
| unset($data['tabs'][0]['entity.node.delete_form']); | |||
| unset($data['tabs'][0]['entity.node.version_history']); | |||
| } | |||
| @@ -56,6 +56,14 @@ arlista.manufacturer.sheet-setting.edit: | |||
| requirements: | |||
| _permission: "arlista manage_pricelists" | |||
| _disable_route_normalizer: "TRUE" | |||
| arlista.manufacturer.sheet-setting.reorder: | |||
| path: "/manufacturer/sheet-settings/reorder" | |||
| defaults: | |||
| _form: '\Drupal\arlista\Form\SheetSetting\SheetSettingReorder' | |||
| _title: "Munkalapok átrendezése" | |||
| requirements: | |||
| _permission: "arlista manage_pricelists" | |||
| _disable_route_normalizer: "TRUE" | |||
| arlista.sheet-setting.delete: | |||
| path: "/manufacturer/{mid}/{sheetIndex}/delete" | |||
| defaults: | |||
| @@ -91,7 +91,7 @@ footer.footer { | |||
| margin-top: 5rem; | |||
| } | |||
| form.arlista-manufacturer-edit-form > a, form > a.edit-link { | |||
| form.arlista-manufacturer-edit-form > a, form > a.edit-link, div.col-lg-6 > a { | |||
| display: block; | |||
| margin-bottom: 1rem; | |||
| } | |||
| @@ -101,10 +101,22 @@ div.custom-items-wrapper.link-container > ul > li > a { | |||
| margin-top: 0.5rem; | |||
| } | |||
| tr.correct-files-uploaded-file.row-for-hiding { | |||
| display: none; | |||
| #draggable > div.draggable-item { | |||
| height: 32px; | |||
| width: 320px; | |||
| } | |||
| span.hide-roller { | |||
| display: none; | |||
| div.field.field--name-field-sheet-settings.field--type-entity-reference > div.field--label { | |||
| font-weight: bold; | |||
| } | |||
| div.region.region-breadcrumb, | |||
| article > h2, | |||
| div.field--name-field-manufacturer-id, | |||
| div.field--name-title, | |||
| div.entity-meta.js-form-wrapper.form-wrapper, | |||
| div.author, | |||
| span.hide-roller, | |||
| tr.correct-files-uploaded-file.row-for-hiding { | |||
| display: none; | |||
| } | |||
| @@ -2,179 +2,200 @@ | |||
| namespace Drupal\arlista\Form\Manufacturer; | |||
| use Drupal\Core\Form\FormStateInterface; | |||
| use Drupal\arlista\Form\ArlistaAbstractForm; | |||
| use Drupal\arlista\Entity\Manufacturer; | |||
| use Drupal\arlista\Entity\Status; | |||
| use Drupal\arlista\Form\ArlistaAbstractForm; | |||
| use Drupal\Core\Form\FormStateInterface; | |||
| use Drupal\Core\Link; | |||
| use Drupal\Core\Url; | |||
| class ManufacturerEdit extends ArlistaAbstractForm { | |||
| private $mid; | |||
| class ManufacturerEdit extends ArlistaAbstractForm | |||
| { | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function getFormId() { | |||
| return 'arlista_manufacturer_edit_form'; | |||
| } | |||
| private $mid; | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function buildForm(array $form, FormStateInterface $form_state, int $mid = null) { | |||
| /* @var $manufacturer Manufacturer */ | |||
| $manufacturer = empty($mid) ? $this->getManufacturerFactory()->create() : $this->getManufacturerFactory()->find($mid); | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function getFormId() | |||
| { | |||
| return 'arlista_manufacturer_edit_form'; | |||
| } | |||
| $this->mid = $mid; | |||
| $form['#prefix'] ='<div class="col-lg-4">'; | |||
| $form[]['link'] = Link::fromTextAndUrl( | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function buildForm(array $form, FormStateInterface $form_state, int $mid = null) | |||
| { | |||
| /* @var $manufacturer Manufacturer */ | |||
| $manufacturer = empty($mid) ? $this->getManufacturerFactory()->create() : $this->getManufacturerFactory()->find($mid); | |||
| $this->mid = $mid; | |||
| $form['#prefix'] = '<div class="col-lg-4">'; | |||
| $form[]['link'] = Link::fromTextAndUrl( | |||
| 'Vissza a gyártókhoz', | |||
| Url::fromRoute('arlista.manufacturer.list') | |||
| )->toRenderable(); | |||
| $form['mid'] = [ | |||
| '#type' => 'hidden', | |||
| '#value' => $mid, | |||
| '#weight' => 10,]; | |||
| $form = $this->getNameField($form, $manufacturer, 20); | |||
| $form['axico_id_name'] = [ | |||
| '#title' => 'Axico cikkszáma', | |||
| '#type' => 'textfield', | |||
| '#required' => true, | |||
| '#default_value' => $manufacturer->getAxicoIdName(), | |||
| '#weight' => 30, | |||
| ]; | |||
| $form = $this->getSifField($form, $manufacturer, 40); | |||
| $form['sif']['#required'] = false; | |||
| $componentBasedOptions = [ | |||
| 0 => 'Termékcsoport alapú besorolás', | |||
| 1 => 'Komponens alapú besorolás' | |||
| ]; | |||
| $form['component_based'] = [ | |||
| '#title' => 'Termékbesorolás', | |||
| '#name' => 'component_based', | |||
| '#type' => 'select', | |||
| '#options' => $componentBasedOptions, | |||
| '#id' => 'component_based_select', | |||
| '#default_value' => [$manufacturer->getComponentBased()], | |||
| '#weight' => 65, | |||
| ]; | |||
| $statusOptions = [ | |||
| Status::PASSIVE => 'Nem', | |||
| Status::ACTIVE => 'Igen' | |||
| ]; | |||
| $form['active_status'] = [ | |||
| '#title' => 'Aktív', | |||
| '#name' => 'active_status', | |||
| '#type' => 'select', | |||
| '#options' => $statusOptions, | |||
| '#id' => 'active_status_select', | |||
| '#default_value' => [$manufacturer->getStatus()], | |||
| '#weight' => 65, | |||
| ]; | |||
| if (!$manufacturer->isNew()) { | |||
| $form['items_wrapper'][]['calculations']['link'] = \Drupal\Core\Link::fromTextAndUrl( | |||
| 'Kalkulációk szerkesztése', | |||
| Url::fromRoute('arlista.manufacturer.calculations.list', [ | |||
| 'mid' => $mid] | |||
| ) | |||
| )->toRenderable(); | |||
| } | |||
| if (!$manufacturer->isNew()) { | |||
| $form['items_wrapper'][]['sheet_settings']['link'] = \Drupal\Core\Link::fromTextAndUrl( | |||
| 'Munkalapok szerkesztése', | |||
| Url::fromRoute('arlista.manufacturer.sheet-setting.edit', [ | |||
| 'mid' => $mid, | |||
| 'sheetIndex' => 0] | |||
| ) | |||
| )->toRenderable(); | |||
| } | |||
| $form['mid'] = [ | |||
| '#type' => 'hidden', | |||
| '#value' => $mid, | |||
| '#weight' => 10]; | |||
| $form = $this->getNameField($form, $manufacturer, 20); | |||
| $form['axico_id_name'] = [ | |||
| '#title' => 'Axico cikkszáma', | |||
| '#type' => 'textfield', | |||
| '#required' => true, | |||
| '#default_value' => $manufacturer->getAxicoIdName(), | |||
| '#weight' => 30, | |||
| ]; | |||
| $form = $this->getSifField($form, $manufacturer, 40); | |||
| $form['sif']['#required'] = false; | |||
| $componentBasedOptions = [ | |||
| 0 => 'Termékcsoport alapú besorolás', | |||
| 1 => 'Komponens alapú besorolás', | |||
| ]; | |||
| $form['component_based'] = [ | |||
| '#title' => 'Termékbesorolás', | |||
| '#name' => 'component_based', | |||
| '#type' => 'select', | |||
| '#options' => $componentBasedOptions, | |||
| '#id' => 'component_based_select', | |||
| '#default_value' => [$manufacturer->getComponentBased()], | |||
| '#weight' => 65, | |||
| ]; | |||
| $statusOptions = [ | |||
| Status::PASSIVE => 'Nem', | |||
| Status::ACTIVE => 'Igen', | |||
| ]; | |||
| $form['active_status'] = [ | |||
| '#title' => 'Aktív', | |||
| '#name' => 'active_status', | |||
| '#type' => 'select', | |||
| '#options' => $statusOptions, | |||
| '#id' => 'active_status_select', | |||
| '#default_value' => [$manufacturer->getStatus()], | |||
| '#weight' => 65, | |||
| ]; | |||
| if (!$manufacturer->isNew()) { | |||
| $form['items_wrapper'][]['calculations']['link'] = \Drupal\Core\Link::fromTextAndUrl( | |||
| 'Kalkulációk szerkesztése', | |||
| Url::fromRoute('arlista.manufacturer.calculations.list', [ | |||
| 'mid' => $mid] | |||
| ) | |||
| )->toRenderable(); | |||
| } | |||
| $form['buttons'] = [ | |||
| '#type' => 'container', | |||
| '#weight' => 1000, | |||
| ]; | |||
| $form['buttons']['arlista_manufacturer_edit_form_submit'] = [ | |||
| '#type' => 'submit', | |||
| '#value' => empty($manufacturer->getName()) ? 'Új gyártó mentése' : $manufacturer->getName() . ' mentése', | |||
| '#attributes' => ['class' => ['btn-success']] | |||
| ]; | |||
| $form['buttons']['deleteManufacturer'] = $this->getDeleteButton($manufacturer); | |||
| $form['buttons']['deleteManufacturer']['#disabled'] = true; | |||
| $form['#suffix'] ='</div>'; | |||
| return $form; | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function validateForm(array &$form, FormStateInterface $form_state) { | |||
| parent::validateForm($form, $form_state); | |||
| foreach ($form_state->getValues() as $key => $value) { | |||
| if ($form_state->hasAnyErrors()) { | |||
| continue; | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function submitForm(array &$form, FormStateInterface $form_state) { | |||
| $values = $form_state->getValues(); | |||
| /* @var $manufacturer Manufacturer */ | |||
| $manufacturer = empty($values['mid']) ? $this->getManufacturerFactory()->create() : $this->getManufacturerFactory()->find($values['mid']); | |||
| $manufacturer->setName($values['name']); | |||
| $manufacturer->setStatus($values['active_status'][0]); | |||
| $manufacturer->setAxicoIdName($values['axico_id_name']); | |||
| $manufacturer->setComponentBased($values['component_based']); | |||
| $manufacturer->setSif($values['sif']); | |||
| $createCalculation = false; | |||
| if ($manufacturer->isNew()) { | |||
| $createCalculation = true; | |||
| } | |||
| if (!$manufacturer->isNew()) { | |||
| $form['items_wrapper'][]['sheet_settings']['link'] = \Drupal\Core\Link::fromTextAndUrl( | |||
| 'Munkalapok szerkesztése', | |||
| Url::fromRoute('arlista.manufacturer.sheet-setting.edit', [ | |||
| 'mid' => $mid, | |||
| 'sheetIndex' => 0] | |||
| ) | |||
| )->toRenderable(); | |||
| } | |||
| $manufacturer = $this->getManufacturerFactory()->save($manufacturer); | |||
| $this->getCacheService()->resetCache(['arlista_manufacturer_list_form']); | |||
| $this->getCacheService()->resetCache(['arlista_component_list_form',0]); | |||
| $this->getCacheService()->resetCache(['arlista_component_list_form',$manufacturer->getId()]); | |||
| if (!$manufacturer->isNew()) { | |||
| $definedSheetSettings = $this->getSheetSettingFactory()->findSheetSettingsByManufacturerId($manufacturer->getId()); | |||
| if (count($definedSheetSettings) > 0) { | |||
| $munkalapSorrendNodeIds = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap_sorrend') | |||
| ->condition('field_manufacturer_id', $manufacturer->getId()) | |||
| ->execute(); | |||
| $form['items_wrapper'][]['sheet_settings']['link'] = \Drupal\Core\Link::fromTextAndUrl( | |||
| 'Munkalapok sorrendje', | |||
| Url::fromRoute('arlista.manufacturer.sheet-setting.reorder', [ | |||
| 'mid' => $mid, | |||
| 'sheetIndex' => 0] | |||
| ) | |||
| )->toRenderable(); | |||
| } | |||
| } | |||
| $form['buttons'] = [ | |||
| '#type' => 'container', | |||
| '#weight' => 1000, | |||
| ]; | |||
| $form['buttons']['arlista_manufacturer_edit_form_submit'] = [ | |||
| '#type' => 'submit', | |||
| '#value' => empty($manufacturer->getName()) ? 'Új gyártó mentése' : $manufacturer->getName() . ' mentése', | |||
| '#attributes' => ['class' => ['btn-success']], | |||
| ]; | |||
| $form['buttons']['deleteManufacturer'] = $this->getDeleteButton($manufacturer); | |||
| $form['buttons']['deleteManufacturer']['#disabled'] = true; | |||
| $form['#suffix'] = '</div>'; | |||
| if ($createCalculation) { | |||
| $categories = $this->getCategoryFactory()->findAll(); | |||
| foreach ($categories as $category) { | |||
| /* @var $calculation Calculation */ | |||
| $calculation = $this->getCalculationFactory()->findByManufacturerAndCategory($manufacturer, $category); | |||
| if (empty($calculation)) { | |||
| $this->getCalculationFactory()->createFor(null, $category, $manufacturer); | |||
| return $form; | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function validateForm(array &$form, FormStateInterface $form_state) | |||
| { | |||
| parent::validateForm($form, $form_state); | |||
| foreach ($form_state->getValues() as $key => $value) { | |||
| if ($form_state->hasAnyErrors()) { | |||
| continue; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| \Drupal::messenger()->addStatus($this->t('Sikeres mentés!')); | |||
| $form_state->setRedirect('arlista.manufacturer.edit', ['mid' => $manufacturer->getId()]); | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function submitForm(array &$form, FormStateInterface $form_state) | |||
| { | |||
| $values = $form_state->getValues(); | |||
| /* @var $manufacturer Manufacturer */ | |||
| $manufacturer = empty($values['mid']) ? $this->getManufacturerFactory()->create() : $this->getManufacturerFactory()->find($values['mid']); | |||
| $manufacturer->setName($values['name']); | |||
| $manufacturer->setStatus($values['active_status'][0]); | |||
| $manufacturer->setAxicoIdName($values['axico_id_name']); | |||
| $manufacturer->setComponentBased($values['component_based']); | |||
| $manufacturer->setSif($values['sif']); | |||
| $createCalculation = false; | |||
| if ($manufacturer->isNew()) { | |||
| $createCalculation = true; | |||
| } | |||
| } | |||
| $manufacturer = $this->getManufacturerFactory()->save($manufacturer); | |||
| $this->getCacheService()->resetCache(['arlista_manufacturer_list_form']); | |||
| $this->getCacheService()->resetCache(['arlista_component_list_form', 0]); | |||
| $this->getCacheService()->resetCache(['arlista_component_list_form', $manufacturer->getId()]); | |||
| if ($createCalculation) { | |||
| $categories = $this->getCategoryFactory()->findAll(); | |||
| foreach ($categories as $category) { | |||
| /* @var $calculation Calculation */ | |||
| $calculation = $this->getCalculationFactory()->findByManufacturerAndCategory($manufacturer, $category); | |||
| if (empty($calculation)) { | |||
| $this->getCalculationFactory()->createFor(null, $category, $manufacturer); | |||
| } | |||
| } | |||
| } | |||
| \Drupal::messenger()->addStatus($this->t('Sikeres mentés!')); | |||
| $form_state->setRedirect('arlista.manufacturer.edit', ['mid' => $manufacturer->getId()]); | |||
| public function deleteEntity(array &$form, FormStateInterface $form_state) { | |||
| $form_state->setRedirect('arlista.manufacturer.delete', ['id' => $this->mid]); | |||
| } | |||
| } | |||
| public function deleteEntity(array &$form, FormStateInterface $form_state) | |||
| { | |||
| $form_state->setRedirect('arlista.manufacturer.delete', ['id' => $this->mid]); | |||
| } | |||
| } | |||
| @@ -5,6 +5,7 @@ namespace Drupal\arlista\Form\SheetSetting; | |||
| use Drupal\Core\Form\FormStateInterface; | |||
| use Drupal\Core\Url; | |||
| use Drupal\arlista\Form\AbstractConfirmForm; | |||
| use \Drupal\node\Entity\Node; | |||
| class ConfirmSheetSettingDelete extends AbstractConfirmForm { | |||
| @@ -31,7 +32,31 @@ class ConfirmSheetSettingDelete extends AbstractConfirmForm { | |||
| public function submitForm(array &$form, FormStateInterface $form_state) { | |||
| //$this->resetEachFormByManufacturerId(['arlista_manufacturer_edit_form'], $this->mid); | |||
| $sheetSetting = $this->getSheetSettingFactory()->findSettingBySheetIndex($this->mid, $this->sheetIndex); | |||
| $munkalapNids = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap') | |||
| ->condition('field_sheet_setting_id', $sheetSetting->getId()) | |||
| ->execute(); | |||
| if(!empty($munkalapNids)){ | |||
| $sheetSettingNode = Node::load(array_pop($munkalapNids)); | |||
| $sheetSettingNodeId = $sheetSettingNode->id(); | |||
| $munkalapSorrendNids = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap_sorrend') | |||
| ->condition('field_manufacturer_id', $sheetSetting->getManufacturerId()) | |||
| ->execute(); | |||
| if(!empty($munkalapSorrendNids)){ | |||
| $sheetSettingSetNode = Node::load(array_pop($munkalapSorrendNids)); | |||
| foreach ($sheetSettingSetNode->get('field_sheet_settings') as $delta => $field_item) { | |||
| if ($field_item->target_id == $sheetSettingNodeId) { | |||
| $sheetSettingSetNode->get('field_sheet_settings')->removeItem($delta); | |||
| $sheetSettingSetNode->save(); | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| $sheetSettingNode->delete(); | |||
| } | |||
| $this->getSheetSettingFactory()->delete($sheetSetting); | |||
| parent::addMessage(); | |||
| $form_state->setRedirect('arlista.manufacturer.sheet-setting.edit',['mid' => $this->mid, 1]); | |||
| } | |||
| @@ -8,6 +8,7 @@ use Drupal\arlista\Entity\Currency; | |||
| use Drupal\arlista\Entity\Manufacturer; | |||
| use Drupal\arlista\Entity\SheetSetting; | |||
| use Drupal\Core\Url; | |||
| use \Drupal\node\Entity\Node; | |||
| class SheetSettingEdit extends ArlistaAbstractForm { | |||
| @@ -219,6 +220,11 @@ class SheetSettingEdit extends ArlistaAbstractForm { | |||
| '#value' => $sheetSetting->getName() . ' - munkalap törlés', | |||
| '#limit_validation_errors' => [], | |||
| ]; | |||
| $form['items_wrapper']['buttons']['help'] = [ | |||
| '#prefix' => '<p class="hint">Új munkalap hozzáadása/átrendezés: Az aktuális listában utolsóként adjon hozzá egy új munkalapot. Az új munkalap mentése után rendezhető át a sorrend a gyártó beállításaiban.</p>', | |||
| '#suffix' => '', | |||
| '#weight' => 1001, | |||
| ]; | |||
| $form['items_wrapper']['#suffix'] = '</div>'; | |||
| return $form; | |||
| } | |||
| @@ -283,10 +289,63 @@ class SheetSettingEdit extends ArlistaAbstractForm { | |||
| $sheetSetting->setDefaultSetting(empty($values['default_setting']) ? 0 : 1); | |||
| $this->getSheetSettingFactory()->save($sheetSetting); | |||
| $this->updateNodeStatus($manufacturer, $sheetSetting); | |||
| \Drupal::messenger()->addStatus('Sikeres mentés!'); | |||
| } | |||
| private function updateNodeStatus($manufacturer, $sheetSetting){ | |||
| $sheetSettingNode = null; | |||
| $sheetSettingNodeId = null; | |||
| $sheetSettingNodeIds = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap') | |||
| ->condition('field_sheet_setting_id', $sheetSetting->getId()) | |||
| ->execute(); | |||
| if(empty($sheetSettingNodeIds)){ | |||
| $sheetSettingNode = Node::create([ | |||
| 'type' => 'munkalap', | |||
| 'title' => '('.$manufacturer->getName() . ') ' . $sheetSetting->getName(), | |||
| 'field_weight' => $sheetSetting->getIndex(), | |||
| 'field_sheet_setting_name' => $sheetSetting->getName(), | |||
| 'field_sheet_setting_id' => $sheetSetting->getId(), | |||
| 'body' => '' | |||
| ]); | |||
| $sheetSettingNode->save(); | |||
| } else { | |||
| $sheetSettingNode = Node::load(array_pop($sheetSettingNodeIds)); | |||
| $sheetSettingNode->title = '('.$manufacturer->getName() . ') ' . $sheetSetting->getName(); | |||
| $sheetSettingNode->field_weight = $sheetSetting->getIndex(); | |||
| $sheetSettingNode->field_sheet_setting_name = $sheetSetting->getName(); | |||
| $sheetSettingNode->field_sheet_setting_id = $sheetSetting->getId(); | |||
| $sheetSettingNode->save(); | |||
| } | |||
| $sheetSettingNodeId = $sheetSettingNode->id(); | |||
| $sheetSettingSetNodeIds = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap_sorrend') | |||
| ->condition('field_manufacturer_id', $sheetSetting->getManufacturerId()) | |||
| ->execute(); | |||
| if(!empty($sheetSettingSetNodeIds)){ | |||
| $sheetSettingSetNode = Node::load(array_pop($sheetSettingSetNodeIds)); | |||
| $isIn = false; | |||
| foreach ($sheetSettingSetNode->get('field_sheet_settings') as $delta => $field_item) { | |||
| if ($field_item->target_id == $sheetSettingNodeId) { | |||
| $isIn = true; | |||
| break; | |||
| } | |||
| } | |||
| if(!$isIn){ | |||
| $sheetSettingSetNode->field_sheet_settings[] = ['target_id' => $sheetSettingNodeId]; | |||
| $sheetSettingSetNode->save(); | |||
| } | |||
| } | |||
| } | |||
| public function deleteEntity(array &$form, FormStateInterface $form_state) { | |||
| $form_state->setRedirect('arlista.sheet-setting.delete', [ | |||
| 'mid' => $this->getQueryValue('mid'), | |||
| @@ -294,22 +353,3 @@ class SheetSettingEdit extends ArlistaAbstractForm { | |||
| } | |||
| } | |||
| //$components = $this->getComponentFactory()->findAll(); | |||
| //$options = []; | |||
| //foreach ($components as $component) { | |||
| // if ($component->getStatus() === 1) { | |||
| // $options[$component->getId()] = $component->getName(); | |||
| // } | |||
| //} | |||
| // | |||
| //$form['columns']['component'] = [ | |||
| // '#title' => 'Válasszon komponenst', | |||
| // '#name' => 'component', | |||
| // '#type' => 'select', | |||
| // '#options' => $options, | |||
| // '#id' => 'component_select', | |||
| // '#default_value' => $sheetSetting->getComponentId() | |||
| //]; | |||
| @@ -0,0 +1,137 @@ | |||
| <?php | |||
| namespace Drupal\arlista\Form\SheetSetting; | |||
| use Drupal\Core\Form\FormStateInterface; | |||
| use Drupal\arlista\Form\ArlistaAbstractForm; | |||
| use Drupal\arlista\Entity\Currency; | |||
| use Drupal\arlista\Entity\Manufacturer; | |||
| use Drupal\arlista\Entity\SheetSetting; | |||
| use Drupal\Core\Url; | |||
| use Drupal\Core\Link; | |||
| use \Drupal\node\Entity\Node; | |||
| class SheetSettingReorder extends ArlistaAbstractForm { | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function getFormId() { | |||
| return 'arlista_manufacturer_sheet_setting_reorder_form'; | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function buildForm(array $form, FormStateInterface $form_state) { | |||
| /* @var $manufacturer Manufacturer */ | |||
| $manufacturer = $this->getManufacturerFactory()->find($this->getQueryValue('mid')); | |||
| $sheetSettings = $this->getSheetSettingFactory()->findSheetSettingsByManufacturerId($manufacturer->getId()); | |||
| $sheetSettingSetNodeId = null; | |||
| $sheetSettingSetNodeIds = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap_sorrend') | |||
| ->condition('field_manufacturer_id', $manufacturer->getId()) | |||
| ->execute(); | |||
| if(empty($sheetSettingSetNodeIds)){ | |||
| $sheetSettingsNids = []; | |||
| foreach($sheetSettings as $sheetSetting){ | |||
| $nids = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap') | |||
| ->condition('field_sheet_setting_id', $sheetSetting->getId()) | |||
| ->execute(); | |||
| if(empty($nids)){ | |||
| $node = Node::create([ | |||
| 'type' => 'munkalap', | |||
| 'title' => '(' . $manufacturer->getName() . ') ' . $sheetSetting->getName(), | |||
| 'field_weight' => $sheetSetting->getIndex(), | |||
| 'field_sheet_setting_name' => $sheetSetting->getName(), | |||
| 'field_sheet_setting_id' => $sheetSetting->getId(), | |||
| 'body' => '' | |||
| ]); | |||
| $node->save(); | |||
| $sheetSettingsNids[] = $node->id(); | |||
| } | |||
| } | |||
| $nids = \Drupal::entityQuery('node') | |||
| ->condition('type', 'munkalap_sorrend') | |||
| ->condition('field_manufacturer_id', $manufacturer->getId()) | |||
| ->execute(); | |||
| if(empty($nids)){ | |||
| $node = Node::create([ | |||
| 'type' => 'munkalap_sorrend', | |||
| 'title' => $manufacturer->getName(), | |||
| 'field_manufacturer_id' => $manufacturer->getId(), | |||
| 'field_sheet_settings' => $sheetSettingsNids, | |||
| 'body' => '' | |||
| ]); | |||
| $node->save(); | |||
| $sheetSettingSetNodeId = $node->id(); | |||
| } | |||
| } else { | |||
| $values = array_values($sheetSettingSetNodeIds); | |||
| $sheetSettingSetNodeId = array_shift($values); | |||
| } | |||
| $entity = Node::load($sheetSettingSetNodeId); | |||
| $view_mode = 'edit'; | |||
| $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); | |||
| $render_controller = \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId()); | |||
| $render_output = $render_controller->view($entity, $view_mode, $langcode); | |||
| $form['items_wrapper']['#prefix'] = '<div class="col-lg-6">'; | |||
| $form['items_wrapper']['sheet_settings'] = []; | |||
| $form['items_wrapper']['sheet_settings']['link']['back'] = \Drupal\Core\Link::fromTextAndUrl( | |||
| 'Vissza a gyártó szerkesztéshez', | |||
| Url::fromRoute('arlista.manufacturer.edit', [ | |||
| 'mid' => $manufacturer->getId()]) | |||
| )->toRenderable(); | |||
| $form['items_wrapper']['sheet_settings']['content'] = $render_output; | |||
| $form['items_wrapper']['sheet_settings']['mid'] = [ | |||
| '#type' => 'hidden', | |||
| '#value' => $manufacturer->getId(),]; | |||
| $url = Url::fromRoute('entity.node.edit_form', ['node' => $sheetSettingSetNodeId]); | |||
| $link = Link::fromTextAndUrl('Sorrend megváltoztatása', $url); | |||
| $form['items_wrapper']['sheet_settings']['link']['forward'] = $link->toRenderable(); | |||
| $form['items_wrapper']['#suffix'] = '</div>'; | |||
| return $form; | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function validateForm(array &$form, FormStateInterface $form_state) { | |||
| } | |||
| /** | |||
| * {@inheritdoc} | |||
| */ | |||
| public function submitForm(array &$form, FormStateInterface $form_state) { | |||
| $values = $form_state->getValues(); | |||
| /* @var $manufacturer Manufacturer */ | |||
| $manufacturer = $this->getManufacturerFactory()->find($values['mid']); | |||
| /* @var $sheetSetting SheetSetting */ | |||
| \Drupal::messenger()->addStatus('Sikeres mentés!'); | |||
| } | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| <div class="arlista-manufacturer-edit-sheet-index"> | |||
| <label for="selected-sheet">{{ manufacturer.name }} - munkalapok</label> | |||
| <select name="manufacturer-edit-selected-sheet-index" id="manufacturer-edit-selected-sheet-index"> | |||
| {% for i in 0..50 %} | |||
| {% for i in 0..26 %} | |||
| <option value ={{ i }} {% if i == sheet_index %} selected="selected" {% endif %} {% if i > 25 %} disabled="true" {% endif %}> | |||
| {{ i+1 }} - munkalap / {% if sheet_settings[i] is defined %} {{ sheet_settings[i].name }} {% endif %} | |||
| </option> | |||