Skip to content
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

WIP: adds datatable to index datatype. #370

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

laurensmartina
Copy link
Contributor

Still not ready to merge, but reviews are highly appreciated.

system/core/pages.php Outdated Show resolved Hide resolved
Copy link
Contributor

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks like this is heading in the right direction. I added a bunch of inline comments.

I think that it would be good to split off the getAuthor() changes into their own commit before finalizing this.

$id = $this->pageListNode->getAttribute('id');
$date = $this->getSortDateTime();
$dataMtx = [
__(self::INDEX_TABLE_COLUMNS_TITLE) => [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if using the translated titles as array indices here is the best approach? I would tend to use some kind of (untranslated) name as the index, and then put the translated title in a field next to class/sort/value?

$date = $this->getSortDateTime();
$dataMtx = [
__(self::INDEX_TABLE_COLUMNS_TITLE) => [
'class' => 'type_'.get_class($this).' '.($this->privateFlag ? 'is-private' : 'is-public'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These things (datatype and private flag) seem to be unrelated to the title, so I wonder if these are appropriate here? Conceptually, they would be a column of their own, but you probably do not want to display them as such.

Maybe these would be more appropriate as classes on the <tr> instead of an individual column? Maybe returned as a special column in this array?

system/core/pages.php Show resolved Hide resolved
system/datatypes/index.php Show resolved Hide resolved
system/datatypes/index.php Show resolved Hide resolved
system/datatypes/index.php Show resolved Hide resolved
ROW;
$tRowItemTpl = <<<ROWITEM
<td class="index-item [[name]] [[class]]" data-sort="[[sort]]">[[value]]</td>
ROWITEM;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I like using these HTML templates like this. They are easy to read, but building HTML from text also seems prone to typos, encoding errors, etc. For forms, we're using this approach because those are complex and very diverse, but here the structure is very repetitive and simple, which means it could be feasible to just build up the DOM in memory like we do elsewhere. This has the advantage that all encoding is done automatically, you can't break the DOM with a typo, you can easily make changes to earlier sections of the DOM, etc.

'value' => $date ? $date->format('Y-m-d') : '',
],
];
return array_intersect_key($dataMtx, array_fill_keys(self::getIndexTableColumns(), ''));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this array_intersect? This seems to drop any keys from $dataMtx that do not appear in getIndexTableColumns(), but in the code I can see that this does not happen? Or is the point that subclasses can delete columns from their superclasses by removing them from getIndexTableColumns (by overriding it)? If so, I'd suggest that those superclasses can also just delete the columns from getIndexData (by overriding that as well), or maybe index page should globally just do this intersect (rather than each datatype having to do it individually)?

__(self::INDEX_TABLE_COLUMNS_TITLE) => [
'class' => 'type_'.get_class($this).' '.($this->privateFlag ? 'is-private' : 'is-public'),
'sort' => preg_replace("/[^A-Za-z0-9]/", '', $this->getTitle()).'_'.$id,
'value' => '<a href="'.$this->language.'/'.$this->pagename.'">'.$this->getTitle().'</a>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be html_value to distinguish between html and text value? Alternatively, the non-HTML values should be htmlspecialchars'd? Alternatively, this could maybe build a DomNode to indicate that it is already HTML (combined with my other suggestion to build a DOM tree instead of an HTML string), and then any strings can be treated as text (and thus encoded).

system/core/pages.php Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants