/** * Return the translatable label. * * @param string $size * @return null|string */ protected function translatableLabel($size = 'sm') { if ($this->object->isTranslatable()) { return '<span class="label label-info label-' . $size . '">' . trans('streams::field.translatable.name') . '</span>'; } return null; }
/** * Handle the command. * * @param StreamSchema $schema */ public function handle(StreamSchema $schema) { $schema->createTable($this->stream); if ($this->stream->isTranslatable()) { $table = $this->stream->getEntryTranslationsTableName(); $schema->createTranslationsTable($table); } }
/** * Handle the command. * * @param Filesystem $files * @param Application $application * @return string */ public function handle(Filesystem $files, Application $application) { $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace())); $model = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryModel.php'; if ($files->exists($model)) { $files->delete($model); } if (!$this->stream->isTranslatable()) { return; } $model = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryTranslationsModel.php'; if ($files->exists($model)) { $files->delete($model); } }
/** * Return the translation foreign key attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } return 'protected $translationForeignKey = \'entry_id\';'; }
/** * Return the entry translation model attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } $namespace = studly_case($stream->getNamespace()); $class = studly_case("{$stream->getNamespace()}_{$stream->getSlug()}") . 'EntryTranslationsModel'; return 'protected $translationModel = \'Anomaly\\Streams\\Platform\\Model\\' . $namespace . '\\' . $class . '\';'; }
/** * Return the translation foreign key attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } $assignments = $stream->getTranslatableAssignments(); if ($assignments->isEmpty()) { return null; } return 'protected $translatedAttributes = [\'' . implode('\', \'', $assignments->fieldSlugs()) . '\'];'; }
/** * Recompile entry models for a given stream. * * @param StreamInterface $stream */ public function recompile(StreamInterface $stream) { // Generate the base model. $this->dispatch(new GenerateEntryModel($stream)); /** * If the stream is translatable generate * the translations model too. */ if ($stream->isTranslatable()) { $this->dispatch(new GenerateEntryTranslationsModel($stream)); } }