/**
  * Guess the assignment names.
  *
  * @param Migration $migration
  */
 public function guess(Migration $migration)
 {
     /**
      * If we don't have any addon then
      * we can't automate anything.
      *
      * @var Addon $addon
      */
     if (!($addon = $migration->getAddon())) {
         return;
     }
     $stream = $migration->getStream();
     $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace'));
     if (!$stream) {
         return;
     }
     $locale = $this->config->get('app.fallback_locale');
     $assignments = $migration->getAssignments();
     foreach ($assignments as &$assignment) {
         foreach (['label', 'warning', 'instructions', 'placeholder'] as $key) {
             if (is_null(array_get($assignment, $locale . '.' . $key))) {
                 $assignment = array_add($assignment, $locale . '.' . $key, $addon->getNamespace('field.' . array_get($assignment, 'field') . '.' . $key . '.' . $stream->getSlug()));
             }
         }
     }
     $migration->setAssignments($assignments);
 }
 /**
  * Normalize the assignments input.
  *
  * @param Migration $migration
  */
 public function normalize(Migration $migration)
 {
     $locale = $this->config->get('app.fallback_locale');
     $stream = $migration->getStream();
     $assignments = $migration->getAssignments();
     foreach ($assignments as $field => &$assignment) {
         /*
          * If the assignment is a simple string
          * then the assignment is the field slug.
          */
         if (is_string($assignment)) {
             $assignment = ['field' => $assignment];
         }
         /*
          * Generally the field will be the
          * array key. Make sure we have one.
          */
         if (!isset($assignment['field'])) {
             $assignment['field'] = $field;
         }
         /*
          * If any of the translatable items exist
          * in the base array then move them up into
          * the translation array.
          */
         foreach (['label', 'warning', 'instructions', 'placeholder'] as $key) {
             if ($value = array_pull($assignment, $key)) {
                 $assignment = array_add($assignment, $locale . '.' . $key, $value);
             }
         }
     }
     $migration->setAssignments($assignments);
 }
 /**
  * Normalize the fields input.
  *
  * @param Migration $migration
  */
 public function normalize(Migration $migration)
 {
     $locale = $this->config->get('app.fallback_locale');
     $fields = $migration->getFields();
     foreach ($fields as $slug => &$field) {
         /*
          * If the field is a simple string then
          * the $slug is used as is and the field
          * must be the field type.
          */
         if (is_string($field)) {
             $field = ['type' => $field];
         }
         if (!isset($field['type'])) {
             throw new \Exception("The [type] parameter must be defined in fields.");
         }
         $field['slug'] = array_get($field, 'slug', $slug);
         $field['namespace'] = array_get($field, 'namespace', $migration->contextualNamespace());
         /*
          * If any of the translatable items exist
          * in the base array then move them up into
          * the translation array.
          */
         foreach (['name', 'instructions', 'placeholder', 'warning'] as $key) {
             if ($value = array_pull($field, $key)) {
                 $field = array_add($field, $locale . '.' . $key, $value);
             }
         }
     }
     $migration->setFields($fields);
 }
예제 #4
0
 /**
  * Read the streams input.
  *
  * @param Migration $migration
  */
 public function read(Migration $migration)
 {
     if (!$migration->getStream()) {
         return;
     }
     $this->normalizer->normalize($migration);
     $this->guesser->guess($migration);
 }
 /**
  * Normalize the streams input.
  *
  * @param Migration $migration
  */
 public function normalize(Migration $migration)
 {
     $stream = $migration->getStream();
     if (is_string($stream)) {
         $stream = ['slug' => $stream];
     }
     $stream['slug'] = array_get($stream, 'slug', $migration->contextualNamespace());
     $stream['namespace'] = array_get($stream, 'namespace', $migration->contextualNamespace());
     $migration->setStream($stream);
 }
 /**
  * Handle the command.
  *
  * @param FieldRepositoryInterface      $fields
  * @param StreamRepositoryInterface     $streams
  * @param AssignmentRepositoryInterface $assignments
  */
 public function handle(FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, AssignmentRepositoryInterface $assignments)
 {
     $addon = $this->migration->getAddon();
     $stream = $this->migration->getStream();
     $namespace = array_get($stream, 'namespace', $this->migration->getNamespace());
     $slug = array_get($stream, 'slug', $addon ? $addon->getSlug() : null);
     $stream = $streams->findBySlugAndNamespace($slug, $namespace);
     foreach ($this->migration->getAssignments() as $field => $assignment) {
         if (is_numeric($field)) {
             $field = $assignment;
         }
         if ($stream && ($field = $fields->findBySlugAndNamespace($field, $namespace))) {
             if ($assignment = $assignments->findByStreamAndField($stream, $field)) {
                 $assignments->delete($assignment);
             }
         }
     }
     $assignments->cleanup();
 }
 /**
  * Guess the stream names.
  *
  * @param Migration $migration
  */
 public function guess(Migration $migration)
 {
     /**
      * If we don't have any addon then
      * we can't automate anything.
      *
      * @var Addon $addon
      */
     if (!($addon = $migration->getAddon())) {
         return;
     }
     $locale = $this->config->get('app.fallback_locale');
     $stream = $migration->getStream();
     foreach (['name', 'description'] as $key) {
         if (is_null(array_get($stream, $locale . '.' . $key))) {
             $stream = array_add($stream, $locale . '.' . $key, $addon->getNamespace('stream.' . array_get($stream, 'slug') . '.' . $key));
         }
     }
     $migration->setStream($stream);
 }
 /**
  * Guess the field names.
  *
  * @param Migration $migration
  */
 public function guess(Migration $migration)
 {
     /**
      * If we don't have any addon then
      * we can't automate anything.
      *
      * @var Addon $addon
      */
     if (!($addon = $migration->getAddon())) {
         return;
     }
     $locale = $this->config->get('app.fallback_locale');
     $fields = $migration->getFields();
     foreach ($fields as &$field) {
         foreach (['name', 'warning', 'instructions', 'placeholder'] as $key) {
             if (is_null(array_get($field, $locale . '.' . $key))) {
                 $field = array_add($field, $locale . '.' . $key, $addon->getNamespace('field.' . array_get($field, 'slug') . '.' . $key));
             }
         }
     }
     $migration->setFields($fields);
 }