New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-29290: As an Editor, I want to have preconfigured "Author" section while creating the content #2392
EZP-29290: As an Editor, I want to have preconfigured "Author" section while creating the content #2392
Conversation
I'd say default for the fieldType should be Empty, not current-user. In fact in more than 10 years using eZ, I have never seen anyone using an author field to store the current user. That info is embedded into content metadata anyway. Whenever an author field is used, it is because the person logged in to input the data is not the author that has to be shown as content creator |
@gggeek thank you for the input. Default option could be easily changed, that's not a problem at all. Prefilling author FieldType with current user's data was present in eZ Publish and eZ Platform v1 so as a matter of consistency we would like to have it also in v2. We also aim to give the Editor possibility to keep current behavior as well. |
…n while creating the content
…dtype' into EZP-29290-prefilling_author_fieldtype # Conflicts: # eZ/Publish/Core/Persistence/Legacy/Content/FieldValue/Converter/AuthorConverter.php # eZ/Publish/Core/Persistence/Legacy/Tests/Content/FieldValue/Converter/AuthorTest.php # eZ/Publish/SPI/Tests/FieldType/AuthorIntegrationTest.php
Few things I'm not sure about:
|
That is probably not the way to do it, as Converter is performed down in Storage Engine and should now know about repository, besides circular references. As for how and the other question maybe @alongosz and @bdunogier can give you some input. |
I changed approach towards implementing this feature in |
/** | ||
* Default value empty. | ||
*/ | ||
const DEFAULT_EMPTY = -1; |
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.
Any reason why you picked -1 over for instance 0? Other cases you found like that?
Asking as I can't right now remember us using negative ints much for int fields.
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 was having hard times to differentiate this value from this which I got from the database for existing ContentTypes (e.g. Article), as we wanted to have prefilling by default there.
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.
Ok, so you're not using 0 as todays default (Null) for data_int1. is casted to int in Storage engine so it becomes 0, which is causing your trouble to decide on value. Right?
Is 0 mapped to DEFAULT_CURRENT_USER somewhere for us btw, so editing existing data works as intended?
@alongosz SIDE: you see any issues with using negative int's for data_int1 column? Or should we rather keep the values in the positive range?
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.
Ok, so you're not using 0 as todays default (Null) for data_int1. is casted to int in Storage engine so it becomes 0, which is causing your trouble to decide on value. Right?
Yes, that was my point.
Is 0 mapped to DEFAULT_CURRENT_USER somewhere for us btw, so editing existing data works as intended?
So you are suggesting switching values? (0, both for prefilling chosen by editor and also for no value from db, 1 for no-prefilling option). It could be confusing, but probably would work.
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.
So you are suggesting switching values?
not necessarily, before even suggesting that I was asking how the system behaves when db has null value. Both when it comes to content type view/edit and for content edit.
context: People upgrading would expect default value to just be current user somehow, so if code here handles that or if we are missing upgrade script where those upgrading can choose between setting these to 1 for user or -1/2 for todays null 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.
@andrerom I tested adding/editing content/content type with/without prefilling, everything seems to be working fine.
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.
@alongosz SIDE: you see any issues with using negative int's for data_int1 column? Or should we rather keep the values in the positive range?
No, this is fine. data_int1
is NOT NULL
anyway, so it has to be something that is non-null and non-zero.
@konradoboza what I don't get is how these constants apply to this solution? What is their purpose?
The naming is very generic and the PhpDoc description says the same thing, which is the perfect example of how not to document code
I can guess based on the other parts of the PR, but if I need to guess it, then it implies it needs an improvement :-)
I prefer you find some better naming so code is either self-commenting or requires only brief explanation. If you can't find better name, then at least provide more descriptive doc block.
... or maybe, since this is a default value, it should belong to the Value
class, not type? Even despite the fact that you're using it in the Type
class.
context: People upgrading would expect default value to just be current user somehow,
@andrerom Actually... No. Why? This is BC break.
I know PMs really want this by default, so AdminUI can set it differently.
From my POV both cases would be BC break, but we should at least make API BC.
@konradoboza I'm wondering if this phase 2 on kernel and repo forms should rather go to master as it's a new feature and not requested by customer so we don't need to rush it. Would that work for you? |
@andrerom sure, it is fine with me. So this one should be rebased to master, how about the other two? |
@konradoboza so which one depends on which? Which PR's are "phase 1", aka minimal scope, and which once are followups to add config in field type? It's the followups I'm suggesting we take to master basically, leaving phase 1 for the shortly upcoming 2.2.2 release. |
@andrerom all three PR's should be treated as one feature, so this is "phase 2", I updated descriptions for ezsystems/repository-forms#251 and ezsystems/ezplatform-admin-ui#586 as they depend on kernel. "Phase 1" was already merged and was about having prefilled Author FieldType, without having a config. Ref: ezsystems/repository-forms#249 |
Ok, clear. Then go for master on the remaining PR's, should not have any conflicts so hopefully simple rebase ;) |
|
db992b2
to
9a91b9c
Compare
Fixed checking if any value came from the database in order to have a default selected radio in the Content Type edit view for existing ones. 9a91b9c#diff-564956cdbfd9b8b86cfb41dc3ddbf243R79 |
return array_map( | ||
function ($constantName) { | ||
return array( | ||
array('defaultAuthor' => $constantName), |
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.
[]
Aka use []
in new code and lines that are changed, and leave array
in places you don't change to unnecessary branch conflicts.
@@ -98,17 +109,17 @@ public function getFieldDefinitionData() | |||
public function getInitialValue() | |||
{ | |||
return new Content\FieldValue( | |||
array( | |||
'data' => array( | |||
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.
can skip these changes
@@ -123,20 +131,20 @@ private function generateXmlString(array $authorValue) | |||
* | |||
* @param string $xmlString XML String stored in storage engine | |||
* | |||
* @return \eZ\Publish\Core\FieldType\Author\Value | |||
* @return 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.
\eZ\Publish\Core\FieldType\Author\Value[]
*/ | ||
private function restoreValueFromXmlString($xmlString) | ||
{ | ||
$dom = new DOMDocument('1.0', 'utf-8'); | ||
$authors = array(); | ||
$authors = []; |
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.
can skip these changes
9a91b9c
to
87481f2
Compare
…n while creating the content
87481f2
to
836060c
Compare
I reverted all the unnecessary changes to array short notation. When there were |
@@ -192,7 +198,7 @@ public function provideInvalidCreationFieldData() | |||
/** | |||
* Get update field externals data. | |||
* | |||
* @return array | |||
* @return AuthorValue |
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.
Please use FQCN
/** | ||
* Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. | ||
* | ||
* @param mixed $fieldSettings |
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.
this is always array, right? Although we can't change interface prototype, I think here we can safely say what we expect.
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.
Should it be changed for every Type
class then? As I see mixed
is used in all FieldTypes which have settings.
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.
No, let's not get out of scope here. It is indeed inconsistent but let's not duplicate past mistakes.
} | ||
|
||
switch ($name) { | ||
case 'defaultAuthor': |
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.
This looks really weird. Probably taken from other implementations, right?
It would make sense if there were more settings. Here what I'd do is early continue: if ($name !== 'defaultAuthor') { continue; }
and get rid of unnecessary indent of the remainder of the code. We should refactor this to switch only when we get to a point where we need more settings, because effort is not gonna be big (it really is a gut feeling when to prepare for possible future and when not to).
If you still prefer the switch, then I'd see logic for the case
moved to a separate method.
Just for readability.
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.
The question is whether we want to be consistent with the other implementations or improve things when it comes to FieldTypes, https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Publish/Core/FieldType/Date/Type.php#L224.
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.
Each Field Type can be treated a separate, so implementations can differ. What we need to avoid is switching code style approaches between valid alternatives. For example pushing towards short array syntax was my mistake, it should be done for entire codebase at once.
In this case I find Field Type implementations quite confusing, so I would rather improve.
That said, maybe just extract contents of this case
block to a separate method? It keeps somewhat consistency and improves readability.
]; | ||
if (!in_array($value, $definedTypes, true)) { | ||
$validationErrors[] = new ValidationError( | ||
"Setting '%setting%' is of unknown type", |
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 this kinda relates to previous comment about naming - this setting is not a "type" to me. It's a default value, right?
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.
Yes, it is actually my bad, $definedValues
sounds much better.
@@ -61,7 +63,7 @@ public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) | |||
*/ | |||
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef) | |||
{ | |||
// Nothing to store | |||
$storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->fieldSettings['defaultAuthor']; |
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.
Please cast it to (int)
or PostgreSQL will die should this data come from an actual web form. Unless it is already casted elsewhere?
@@ -22,6 +27,7 @@ | |||
*/ | |||
class AuthorTest extends TestCase | |||
{ | |||
const ADMINISTRATOR_USER_ID = 14; |
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.
It doesn't seem it is used.
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.
Great catch! I must have forgotten to remove it alongside with the mocks from the previous implementation.
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\AuthorConverter; | ||
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition as PersistenceFieldDefinition; |
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.
The naming convention is rather SPIFieldDefinition
.
/** | ||
* Default value empty. | ||
*/ | ||
const DEFAULT_EMPTY = -1; |
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.
@alongosz SIDE: you see any issues with using negative int's for data_int1 column? Or should we rather keep the values in the positive range?
No, this is fine. data_int1
is NOT NULL
anyway, so it has to be something that is non-null and non-zero.
@konradoboza what I don't get is how these constants apply to this solution? What is their purpose?
The naming is very generic and the PhpDoc description says the same thing, which is the perfect example of how not to document code
I can guess based on the other parts of the PR, but if I need to guess it, then it implies it needs an improvement :-)
I prefer you find some better naming so code is either self-commenting or requires only brief explanation. If you can't find better name, then at least provide more descriptive doc block.
... or maybe, since this is a default value, it should belong to the Value
class, not type? Even despite the fact that you're using it in the Type
class.
context: People upgrading would expect default value to just be current user somehow,
@andrerom Actually... No. Why? This is BC break.
I know PMs really want this by default, so AdminUI can set it differently.
From my POV both cases would be BC break, but we should at least make API BC.
$incomingSettingsHash['defaultAuthor'] = Type::DEFAULT_EMPTY; | ||
break; | ||
default: | ||
$incomingSettingsHash['defaultAuthor'] = Type::DEFAULT_CURRENT_USER; |
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.
as I've said above - it's a BC break.
{% endif %} | ||
{{ block( 'settings_defaultvalue' ) }} | ||
</ul> | ||
{% endblock %} |
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.
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.
It looks okay.
Suggestions from @alongosz applied. Regarding BC: in v1 and Legacy we had prefilled Author data by default. Within the scope of this (and related) PR we give editors an option in CT creation view. Existing CT's (e.g. article) will be prefilled by default. /cc @lserwatka |
a0cd246
to
d6728bd
Compare
…n while creating the content
d6728bd
to
7f4bc34
Compare
@barbaragr let's proceed with QA here. |
Code looks now good. If we want to merge a BC break, at least please add a note in I'm against making BC breaks in places we have a choice (e.g. not forced by bugs), but since this is what PMs want, BC note is the least we could do. |
BC break note added in: #2411 |
master
JIRA excerpt:
This is the kernel implementation of this feature. It is followed by the changes in
repository-forms
andadmin-ui-bundle
which will enable a user to choose whether Author FieldType should be prefilled by default from the ContentType creation view.Is required by:
TODO:
$ composer fix-cs
).