/** * Run the seeder. */ public function run() { if ($type = $this->types->findBySlug('default_posts')) { $this->types->delete($type); } /* @var TypeInterface $type */ $type = $this->types->truncate()->create(['en' => ['name' => 'Default', 'description' => 'A simple post type.'], 'slug' => 'default', 'theme_layout' => 'theme::layouts/default.twig', 'layout' => '{{ post.content|raw }}']); $stream = $type->getEntryStream(); $this->assignments->create(['stream' => $stream, 'field' => $this->fields->findBySlugAndNamespace('content', 'posts')]); }
/** * Run the seeder. */ public function run() { if ($type = $this->types->findBySlug('default_pages')) { $this->types->delete($type); } /* @var TypeInterface $type */ $type = $this->types->truncate()->create(['en' => ['name' => 'Default', 'description' => 'A simple page type.'], 'slug' => 'default', 'handler' => 'anomaly.extension.default_page_handler', 'theme_layout' => 'theme::layouts/default.twig', 'layout' => '<h1>{{ page.title }}</h1> {{ page.content|raw }}']); $stream = $type->getEntryStream(); $this->assignments->create(['stream' => $stream, 'field' => $this->fields->findBySlugAndNamespace('content', 'pages')]); }
/** * Migrate the migration. * * @param Migration $migration */ public function migrate(Migration $migration) { $this->input->read($migration); if (!($stream = $migration->getStream())) { return; } $assignments = $migration->getAssignments(); $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace')); if (!$stream) { return; } foreach ($assignments as $assignment) { /* * Make sure that we can find the * field before we try assigning it. * * @var FieldInterface */ if (!($field = $this->fields->findBySlugAndNamespace($assignment['field'], $stream->getNamespace()))) { continue; } $assignment['field'] = $field; $assignment['stream'] = $stream; /* * Check if the field is already * assigned to the stream first. */ if ($this->assignments->findByStreamAndField($stream, $field)) { continue; } $this->assignments->create($assignment); } }
/** * Handle the command. * * @param AssignmentRepositoryInterface $assignments */ public function handle(AssignmentRepositoryInterface $assignments) { if ($this->builder->getFormOption('auto_assign') === true && $this->builder->getFormMode() === 'create') { $field = $this->builder->getFormEntry(); $stream = $this->builder->getStream(); $assignments->create(['stream_id' => $stream->getId(), 'field_id' => $field->getId()]); } }
/** * Handle the command. * * @param AssignmentRepositoryInterface $assignments * @return AssignmentInterface */ public function handle(AssignmentRepositoryInterface $assignments) { return $assignments->create($this->stream, $this->field, $this->attributes); }
/** * Handle the command. * * @param AssignField $command * @return AssignmentInterface */ public function handle(AssignField $command) { return $this->assignments->create($command->getStream(), $command->getField(), $command->getAttributes()); }
/** * Handle the command. * * @param MigrateAssignments $command */ public function handle(MigrateAssignments $command) { $migration = $command->getMigration(); $stream = $migration->getStream(); $fields = $migration->getAssignments(); $namespace = $migration->getNamespace(); if (!$fields) { return; } $addon = $migration->getAddon(); $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null))); foreach ($fields as $field => $assignment) { if (is_numeric($field)) { $field = $assignment; $assignment = []; } if (!is_array($assignment)) { throw new \Exception('The assignment must be an array or field_slug value.'); } /** * If the label exists in the base array * then move it to the translated array * for the default locale. */ if ($label = array_pull($assignment, 'label')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.label', $label); } /** * If the label is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.label')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.label', $addon ? $addon->getNamespace("field.{$field}.label.{$stream->getSlug()}") : null); } /** * If the instructions exists in the base array * then move it to the translated array * for the default locale. */ if ($instructions = array_pull($assignment, 'instructions')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.instructions', $instructions); } /** * If the instructions is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.instructions')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.instructions', $addon ? $addon->getNamespace("field.{$field}.instructions.{$stream->getSlug()}") : null); } /** * If the placeholder exists in the base array * then move it to the translated array * for the default locale. */ if ($placeholder = array_pull($assignment, 'placeholder')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.placeholder', $placeholder); } /** * If the placeholder is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.placeholder')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.placeholder', $addon ? $addon->getNamespace("field.{$field}.placeholder.{$stream->getSlug()}") : null); } /** * If the warning exists in the base array * then move it to the translated array * for the default locale. */ if ($warning = array_pull($assignment, 'warning')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.warning', $warning); } /** * If the instructions is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.warning')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.warning', $addon ? $addon->getNamespace("field.{$field}.warning.{$stream->getSlug()}") : null); } $field = $this->fields->findBySlugAndNamespace($field, $stream->getNamespace()); if ($field) { $this->assignments->create(array_merge($assignment, compact('field', 'stream'))); } } }