Skip to content

Commit

Permalink
#8 Create API support for entities, #33 Duplicate button in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
UltimateModuleCreator committed Jul 2, 2020
1 parent 24e18e1 commit 546abbe
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/Umc/CoreBundle/Resources/views/edit/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@
<nav class="float-right">
<ul class="nav nav-pills">
<li class="nav-item"">
<button data-bind="click: togglePanel" class="nav-link btn btn-link" href="#">
<button data-bind="click: togglePanel" class="nav-link btn btn-link" href="#" title="Toggle">
<i data-bind="class: collapseClass"></i>
</button>
</li>
<li class="nav-item"">
<button class="nav-link btn btn-link" href="#" title="Duplicate" data-bind="click: function (data, event) {$parent.addChild(data.toParams(), '{{ child.code }}')}">
<i class="fa fa-2x fa-copy"></i>
</button>
</li>
<li class="nav-item">
<button data-bind="click: function (data, event) {$parent.removeChild(data, '{{ child.code }}')}" class="nav-link btn btn-link" href="#">
<button data-bind="click: function (data, event) {$parent.removeChild(data, '{{ child.code }}')}" class="nav-link btn btn-link" href="#" title="Delete">
<i class="fa fa-2x fa-trash"></i>
</button>
</li>
Expand Down
3 changes: 3 additions & 0 deletions src/Umc/MagentoBundle/Resources/config/source/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,6 @@
-
source: "@UmcMagento/source/view/frontend/layout/default.xml"
label: "Default layout handle"
-
source: "@UmcMagento/source/etc/webapi.xml"
label: "Webapi declaration file"
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ declare(strict_types=1);
namespace {{ module.getNamespace() }}\{{ module.getModuleName() }}\Api\Data;
{{ sortStart() }}
use Magento\Framework\Api\SearchCriteriaInterface;
use {{ entity.getInterface()}};
{{ sortEnd() }}
/**
* @api
Expand All @@ -16,14 +13,14 @@ interface {{ entity.getNameSingular()|camel|ucfirst }}SearchResultInterface
/**
* get items
*
* @return {{ entity.getInterface(true)}}[]
* @return \{{ entity.getInterface()}}[]
*/
public function getItems();
/**
* Set items
*
* @param {{ entity.getInterface(true)}}[] $items
* @param \{{ entity.getInterface()}}[] $items
* @return $this
*/
public function setItems(array $items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface {{ entity.getNameSingular()|camel|ucfirst }}ListRepositoryInterface
{
/**
* @param SearchCriteriaInterface $searchCriteria
* @return {{ entity.getNameSingular()|camel|ucfirst }}SearchResultsInterface
* @return {{ entity.getNameSingular()|camel|ucfirst }}SearchResultInterface
* @throws LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>{{ formatLicense(module, 'xml')|raw }}
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
{% for entity in module.getEntities() %}
<!-- {{ entity.getLabelSingular() }} -->
<route url="/V1/{{ entity.getNameSingular()|camel }}/:{{ entity.getPk()|camel }}" method="GET">
<service class="{{ entity.getRepoInterface() }}" method="get"/>
<resources>
<resource ref="{{ entity.getAclName() }}"/>
</resources>
</route>
<route url="/V1/{{ entity.getNameSingular()|camel }}/search" method="GET">
<service class="{{ entity.getListRepoInterface() }}" method="getList"/>
<resources>
<resource ref="{{ entity.getAclName() }}"/>
</resources>
</route>
<route url="/V1/{{ entity.getNameSingular()|camel }}" method="POST">
<service class="{{ entity.getRepoInterface() }}" method="save"/>
<resources>
<resource ref="{{ entity.getAclName() }}"/>
</resources>
</route>
<route url="/V1/{{ entity.getNameSingular()|camel }}/:{{ entity.getPk()|camel }}" method="PUT">
<service class="{{ entity.getRepoInterface() }}" method="save"/>
<resources>
<resource ref="{{ entity.getAclName() }}"/>
</resources>
</route>
<route url="/V1/{{ entity.getNameSingular()|camel }}/:{{ entity.getPk()|camel }}" method="DELETE">
<service class="{{ entity.getRepoInterface() }}" method="deleteById"/>
<resources>
<resource ref="{{ entity.getAclName() }}"/>
</resources>
</route>
{% endfor %}
</routes>

0 comments on commit 546abbe

Please sign in to comment.