/** * Boot the model */ public static function boot() { NodeSource::saving(function (NodeSourceContract $nodeSource) { if (empty($nodeSource->getNodeName()) || is_null($nodeSource->getNodeName())) { $nodeSource->setNodeNameFromTitle(); } }); }
/** * Overloading default Translatable functionality for * creating a new translation * * @param string $locale * @return Model */ public function getNewTranslation($locale) { $nodeSource = NodeSource::newWithType($locale, $this->getNodeTypeName()); $this->translations->add($nodeSource); return $nodeSource; }
/** * @param Request $request * @param NodeSource $source */ protected function validateEditForm(Request $request, NodeSource $source) { $this->validateForm(source_form_name($source->source_type, true), $request, ['node_name' => 'max:255|alpha_dash|unique:node_sources,node_name,' . $source->getKey()]); }
/** @test */ function it_saves_with_dirty_translations_on_create() { $node = $this->getNode(); $node->fill(['visible' => 0, 'en' => ['title' => 'English Title', 'description' => 'English Description'], 'tr' => ['title' => 'Türkçe Başlık', 'description' => 'Türkçe Açıklama']]); $this->assertCount(2, $node->translations); $this->assertCount(0, NodeSource::all()); $this->assertTrue($node->save()); $node->load('translations'); $this->assertCount(2, $node->translations); $this->assertCount(2, NodeSource::all()); }
/** @test */ function it_checks_if_source_is_dirty_after_created() { $nodeSource = $this->getNodeSource(); $this->populateNodeSource($nodeSource); $nodeSource->area = 10000; $nodeSource->save(); $this->assertFalse($nodeSource->isDirty()); $nodeSource->area = 20000; $this->assertTrue($nodeSource->isDirty()); $nodeSource->save(); $this->assertFalse($nodeSource->isDirty()); $nodeSource->title = 'Different Title'; $this->assertTrue($nodeSource->isDirty()); $nodeSource->save(); $this->assertFalse($nodeSource->isDirty()); // Find and check again $nodeSource = NodeSource::find($nodeSource->getKey()); $this->assertFalse($nodeSource->isDirty()); $nodeSource->area = 30000; $this->assertTrue($nodeSource->isDirty()); $nodeSource->save(); $this->assertFalse($nodeSource->isDirty()); }
/** * Deletes a translation * * @param int $id * @return Response */ public function destroyTranslation($id) { $this->authorize('EDIT_NODES'); $source = NodeSource::findOrFail($id); $node = $source->node; if ($response = $this->validateNodeIsNotLocked($node)) { return $response; } // Prevent deletion if there is only one translation if (count($node->translations) > 1) { $source->delete(); } $node->load('translations'); $this->notify('general.destroyed_translation', 'deleted_node_translation', $node); return redirect()->route('reactor.nodes.edit', [$node->getKey(), $node->translateOrfirst()->getKey()]); }