-
Notifications
You must be signed in to change notification settings - Fork 8
Example for admin metadata implementation, #19
Conversation
*/ | ||
public function get($key) | ||
{ | ||
if (!isset($this->supported[$key])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would you fill that array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was just junk from the WIP.
16c5c92
to
719c836
Compare
|
||
use Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource; | ||
|
||
interface DescriptionEnricherInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming this with the more apt term (imo) "augmenter"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use Enhancer as with the RoutingBundle - I think the semantic is the same /cc @dbu
public function getPayloadDescriptionFor(CmfResource $resource) | ||
{ | ||
$type = $resource->getPayloadType(); | ||
$payload = $resource->getPayload(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to check if payload is an object. At the moment, it can be anything: https://github.com/symfony-cmf/resource/blob/master/Repository/Resource/CmfResource.php#L40-L48 (I even believe we use it as string in the ResourceBundle atm)
That was a wrong comment. However, I don't see why we have to know the payload? Removing this and injecting the resource in the enricher would allow us to use any puli resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case we would need to inject tge Resource into the Description, making it a Resource Description and not a Payload Description (what I see it as now) but, what you suggest probably makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, the Description
now accepts a PuliResource
and we pass only the Description
to the enhance
(renamed from enrich
) method of the Enhancer
.
/** | ||
* Return the descriptors value for the given key. | ||
* | ||
* The key should be one of the constants defined in this class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not "this" class.
9932069
to
b11a77c
Compare
public function set($key, $value) | ||
{ | ||
$this->descriptors[$key] = $value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about also implementing the other methods mentioned in http://symfony.com/doc/current/contributing/code/conventions.html#method-names ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we are missing has()
and possibly all()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something to set several descriptors in one call, by providing a hashmap that is merged with $this->descriptors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that would be merge()
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or setDescriptor($key, $value) and setDescriptors($descriptors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But would setDescriptors
replace all the descriptors or merge them? I would assume without prior knowledge that it would replace them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, true. maybe addDescriptors? mergeDescriptors feels strange. that adding something that already exists overwrites the existing value seems no big surprise to me, and we can state it explicitly in the phpdoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer merge, as that correlates with array_merge
which is what you are actually doing. However, I think the ParameterBag
uses add()
with the same semantic.
I guess suffixing Descriptor
makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I understand the reasons behind the Also, why not add these constants to the |
My main concern is to try and avoid a situation where one implementation uses a different key/descriptor than another implementation for the same thing. But I don't really see any alternative to defining a canonical set of "descriptors". How else could we "solve" this problem?
It just seemed a little bit more semantic: $description->set(Descriptor::TITLE, 'Hello');
$description->set(Descriptor::LINK_EDIT_HTML, 'http://foo/bar.html'); vs. $description->set(Description::TITLE, 'Hello');
$description->set(Description::LINK_EDIT_HTML, 'http://foo/bar.html'); and it separated the responsiblitiy of storing these values into a separate Don't feel too strongly about it however. |
class Description | ||
{ | ||
/** | ||
* @var array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the values in this array? strings, or something more complex? a list of label => url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can limit them to be scalar values. If there is a use case for array values we could allow that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should allow arrays also, f.e. to indicate the valid child payload types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ba30ba0
to
0b75002
Compare
/** | ||
* Return true if the provider supports the given type. | ||
* | ||
* @param CmfResource $resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Cmf/Puli
@wouterj could you have a look, I anticipate making further changes but I think it would be good to get this in to facilitate further work. |
If everything works as expected from your point of view, let's just merge. We can improve it while it's in the master branch. I agree with the concept behind this PR and don't see major problems in a quick review. I don't have time to test it atm. |
See #18
Descriptors
A description is just an key / value store and passed to any number of
supprorting "enrichers" (e.g. SonataEnricher, SyliusEnricher) which add any
information.
In order to ensure interoperability a
Descriptor
class is given whichprovides constant values for use as descriptor keys, e.g.
LINK_EDIT_HTML
,TYPE_ALIAS
,TITLE
.Use is as follows:
Enhancers
Enhancers included in this PR: