You are here

MappingStepService.php in GatherContent 8.5

Same filename and directory in other branches
  1. 8.4 gathercontent_ui/src/Form/MappingEditSteps/MappingStepService.php

File

gathercontent_ui/src/Form/MappingEditSteps/MappingStepService.php
View source
<?php

namespace Drupal\gathercontent_ui\Form\MappingEditSteps;

use Drupal\gathercontent\Entity\MappingInterface;

/**
 * Class MappingStepFactory.
 *
 * @package Drupal\gathercontent_ui\Form\MappingEditSteps
 */
class MappingStepService {

  /**
   * New step.
   *
   * @var null|object
   */
  protected $newStep;

  /**
   * Edit step.
   *
   * @var null|object
   */
  protected $editStep;

  /**
   * Entity reference step.
   *
   * @var null|object
   */
  protected $entityReferenceStep;

  /**
   * Returns new step object.
   *
   * @param \Drupal\gathercontent\Entity\MappingInterface $mapping
   *   Mapping object.
   * @param array $template
   *   Template array.
   *
   * @return \Drupal\gathercontent_ui\Form\MappingEditSteps\MappingStepNew
   *   MappingStepNew object.
   */
  public function getNewStep(MappingInterface $mapping, array $template) {
    if ($this->newStep === NULL) {
      $this->newStep = new MappingStepNew($mapping, $template);
    }
    return $this->newStep;
  }

  /**
   * Returns new step object.
   *
   * @param \Drupal\gathercontent\Entity\MappingInterface $mapping
   *   Mapping object.
   * @param array $template
   *   Template array.
   *
   * @return \Drupal\gathercontent_ui\Form\MappingEditSteps\MappingStepEdit
   *   MappingStepEdit object.
   */
  public function getEditStep(MappingInterface $mapping, array $template) {
    if ($this->editStep === NULL) {
      $this->editStep = new MappingStepEdit($mapping, $template);
    }
    return $this->editStep;
  }

  /**
   * Returns new step object.
   *
   * @param \Drupal\gathercontent\Entity\MappingInterface $mapping
   *   Mapping object.
   * @param array $template
   *   Template array.
   *
   * @return \Drupal\gathercontent_ui\Form\MappingEditSteps\MappingStepEntityReference
   *   MappingStepEntityReference object.
   */
  public function getEntityReferenceStep(MappingInterface $mapping, array $template) {
    if ($this->entityReferenceStep === NULL) {
      $this->entityReferenceStep = new MappingStepEntityReference($mapping, $template);
    }
    if ($this->newStep !== NULL) {
      $this->entityReferenceStep
        ->setEntityReferenceFields($this->newStep
        ->getEntityReferenceFields());
      $this->entityReferenceStep
        ->setEntityReferenceFieldsOptions($this->newStep
        ->getEntityReferenceFieldsOptions());
    }
    if ($this->editStep !== NULL) {
      $this->entityReferenceStep
        ->setEntityReferenceFields($this->editStep
        ->getEntityReferenceFields());
      $this->entityReferenceStep
        ->setEntityReferenceFieldsOptions($this->editStep
        ->getEntityReferenceFieldsOptions());
    }
    return $this->entityReferenceStep;
  }

}

Classes

Namesort descending Description
MappingStepService Class MappingStepFactory.