/** * Show the form for creating a new resource. * * @param int $id * @return \Illuminate\Http\Response */ public function create($id) { $this->authorize('EDIT_NODETYPES'); $nodetype = NodeType::findOrFail($id); $form = $this->getCreateForm($id); return $this->compileView('nodefields.create', compact('id', 'form', 'nodetype')); }
/** @test */ function it_destroys_a_node_type() { $builderService = $this->prophesize('Nuclear\\Hierarchy\\Contract\\Builders\\BuilderServiceContract'); // This part is for the sake of setting the test up $builderService->buildTable('project', Argument::type('int'))->shouldBeCalled(); $repository = new NodeTypeRepository($builderService->reveal()); $nodeType = $repository->create(['name' => 'project', 'label' => 'Project']); $this->assertEquals(1, NodeType::count()); $builderService->destroyTable('project', [], $nodeType->getKey())->shouldBeCalled(); $repository->destroy($nodeType->getKey()); $this->assertEquals(0, NodeType::count()); }
/** * @param Node $parent * @return array */ protected function compileAllowedNodeTypes(Node $parent = null) { $nodeTypes = NodeType::whereVisible(1)->forNodes()->lists('label', 'id')->toArray(); if ($parent) { $allowed = json_decode($parent->getNodeType()->allowed_children); if (count($allowed)) { foreach ($nodeTypes as $key => $value) { if (!in_array($key, $allowed)) { unset($nodeTypes[$key]); } } } } return $nodeTypes; }
/** * Remakes sources */ protected function remakeSources(NodeType $nodeType) { foreach ($this->translations as $translation) { $source = $translation->getNewSourceModel($nodeType->getName()); $source->id = $translation->getKey(); $translation->relations['source'] = $source; } $this->propagateIdToSources(); }
/** * @return array */ protected function compileAllowedNodeTypes() { return NodeType::whereVisible(1)->forMailings()->lists('label', 'id')->toArray(); }
/** * List the specified resource fields. * * @param int $id * @return Response */ public function nodes($id) { $this->authorize('ACCESS_NODES'); $nodetype = NodeType::findOrFail($id); $modelName = $nodetype->isTypeMailing() ? MailingNode::class : Node::class; $nodes = $modelName::where('node_type_id', $nodetype->getKey())->sortable()->paginate(); return $this->compileView('nodetypes.nodes', compact('nodetype', 'nodes'), trans('nodes.title')); }
protected function getNodeType($attributes = []) { $attributes = !empty($attributes) ? $attributes : ['name' => 'project', 'label' => 'Project', 'description' => '']; return NodeType::create($attributes); }