Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 679fc76

Browse files
Store the context in the View (#50)
* Store the context in the View * Use has
1 parent dc3a02d commit 679fc76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+338
-363
lines changed

vendor-extra/JatsContentBundle/src/ViewConverter/BoldVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function __construct(ViewConverter $converter)
2121
$this->converter = $converter;
2222
}
2323

24-
protected function doVisit(Element $object, View $view, array &$context = []) : View
24+
protected function doVisit(Element $object, View $view) : View
2525
{
26-
return $view->withArgument('text', $this->convertChildren($object, $context));
26+
return $view->withArgument('text', $this->convertChildren($object, $view->getContext()));
2727
}
2828

2929
protected function possibleTemplate() : string

vendor-extra/JatsContentBundle/src/ViewConverter/FrontArticleTitleContentHeaderVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(ViewConverter $converter)
2121
$this->converter = $converter;
2222
}
2323

24-
protected function doVisit(Element $object, View $view, array &$context = []) : View
24+
protected function doVisit(Element $object, View $view) : View
2525
{
2626
$title = $object->ownerDocument->xpath()
2727
->firstOf('jats:article-meta/jats:title-group/jats:article-title', $object);
@@ -32,7 +32,7 @@ protected function doVisit(Element $object, View $view, array &$context = []) :
3232

3333
return $view->withArgument(
3434
'contentTitle',
35-
$this->converter->convert($title, '@LiberoPatterns/heading.html.twig', $context)->getArguments()
35+
$this->converter->convert($title, '@LiberoPatterns/heading.html.twig', $view->getContext())->getArguments()
3636
);
3737
}
3838

vendor-extra/JatsContentBundle/src/ViewConverter/FrontItemTagsVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(ViewConverter $converter)
2424
$this->converter = $converter;
2525
}
2626

27-
protected function doVisit(Element $object, View $view, array &$context = []) : View
27+
protected function doVisit(Element $object, View $view) : View
2828
{
2929
/** @var DOMNodeList|Element[] $keywordGroups */
3030
$keywordGroups = $object->ownerDocument->xpath()
@@ -40,7 +40,7 @@ protected function doVisit(Element $object, View $view, array &$context = []) :
4040
function (View $tagList) : array {
4141
return $tagList->getArguments();
4242
},
43-
$this->convertList($keywordGroups, '@LiberoPatterns/tag-list.html.twig', $context)
43+
$this->convertList($keywordGroups, '@LiberoPatterns/tag-list.html.twig', $view->getContext())
4444
)
4545
);
4646
}

vendor-extra/JatsContentBundle/src/ViewConverter/FrontSubjectGroupContentHeaderVisitor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(ViewConverter $converter, TranslatorInterface $trans
3131
$this->translator = $translator;
3232
}
3333

34-
protected function doVisit(Element $object, View $view, array &$context = []) : View
34+
protected function doVisit(Element $object, View $view) : View
3535
{
3636
/** @var DOMNodeList|Element[] $subjects */
3737
$subjects = $object->ownerDocument->xpath()->evaluate(
@@ -47,13 +47,16 @@ protected function doVisit(Element $object, View $view, array &$context = []) :
4747
'categories',
4848
[
4949
'attributes' => [
50-
'aria-label' => $this->translate('libero.patterns.content_header.categories.label', $context),
50+
'aria-label' => $this->translate(
51+
'libero.patterns.content_header.categories.label',
52+
$view->getContext()
53+
),
5154
],
5255
'items' => array_map(
5356
function (View $link) : array {
5457
return ['content' => $link->getArguments()];
5558
},
56-
$this->convertList($subjects, '@LiberoPatterns/link.html.twig', $context)
59+
$this->convertList($subjects, '@LiberoPatterns/link.html.twig', $view->getContext())
5760
),
5861
]
5962
);

vendor-extra/JatsContentBundle/src/ViewConverter/HeadingVisitor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public function __construct(ViewConverter $converter)
2121
$this->converter = $converter;
2222
}
2323

24-
protected function doVisit(Element $object, View $view, array &$context = []) : View
24+
protected function doVisit(Element $object, View $view) : View
2525
{
26-
if (isset($context['level'])) {
27-
$view = $view->withArgument('level', $context['level']);
26+
if ($view->hasContext('level')) {
27+
$view = $view->withArgument('level', $view->getContext('level'));
2828
}
2929

30-
return $view->withArgument('text', $this->convertChildren($object, $context));
30+
return $view->withArgument('text', $this->convertChildren($object, $view->getContext()));
3131
}
3232

3333
protected function expectedTemplate() : string

vendor-extra/JatsContentBundle/src/ViewConverter/ItalicVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function __construct(ViewConverter $converter)
2121
$this->converter = $converter;
2222
}
2323

24-
protected function doVisit(Element $object, View $view, array &$context = []) : View
24+
protected function doVisit(Element $object, View $view) : View
2525
{
26-
return $view->withArgument('text', $this->convertChildren($object, $context));
26+
return $view->withArgument('text', $this->convertChildren($object, $view->getContext()));
2727
}
2828

2929
protected function possibleTemplate() : string

vendor-extra/JatsContentBundle/src/ViewConverter/KeywordGroupTagListVisitor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(ViewConverter $converter, TranslatorInterface $trans
3131
$this->translationKeys = $translationKeys;
3232
}
3333

34-
protected function doVisit(Element $object, View $view, array &$context = []) : View
34+
protected function doVisit(Element $object, View $view) : View
3535
{
3636
$title = $object->ownerDocument->xpath()
3737
->firstOf('jats:title', $object);
@@ -46,11 +46,12 @@ protected function doVisit(Element $object, View $view, array &$context = []) :
4646
$type = $object->getAttribute('kwd-group-type');
4747

4848
if ($title instanceof Element) {
49-
$title = $this->converter->convert($title, '@LiberoPatterns/heading.html.twig', $context)->getArguments();
49+
$title = $this->converter->convert($title, '@LiberoPatterns/heading.html.twig', $view->getContext())
50+
->getArguments();
5051
} elseif (!isset($this->translationKeys[$type])) {
5152
return $view;
5253
} else {
53-
$title = ['text' => $this->translate($this->translationKeys[$type], $context)];
54+
$title = ['text' => $this->translate($this->translationKeys[$type], $view->getContext())];
5455
}
5556

5657
return $view
@@ -62,7 +63,7 @@ protected function doVisit(Element $object, View $view, array &$context = []) :
6263
function (View $link) : array {
6364
return ['content' => $link->getArguments()];
6465
},
65-
$this->convertList($keywords, '@LiberoPatterns/link.html.twig', $context)
66+
$this->convertList($keywords, '@LiberoPatterns/link.html.twig', $view->getContext())
6667
),
6768
]
6869
);

vendor-extra/JatsContentBundle/src/ViewConverter/LinkVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public function __construct(ViewConverter $converter)
2323
$this->converter = $converter;
2424
}
2525

26-
protected function doVisit(Element $object, View $view, array &$context = []) : View
26+
protected function doVisit(Element $object, View $view) : View
2727
{
28-
return $view->withArgument('text', $this->convertChildren($object, $context));
28+
return $view->withArgument('text', $this->convertChildren($object, $view->getContext()));
2929
}
3030

3131
protected function expectedTemplate() : string

vendor-extra/JatsContentBundle/src/ViewConverter/ParagraphVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public function __construct(ViewConverter $converter)
2323
$this->converter = $converter;
2424
}
2525

26-
protected function doVisit(Element $object, View $view, array &$context = []) : View
26+
protected function doVisit(Element $object, View $view) : View
2727
{
28-
return $view->withArgument('text', $this->convertChildren($object, $context));
28+
return $view->withArgument('text', $this->convertChildren($object, $view->getContext()));
2929
}
3030

3131
protected function possibleTemplate() : string

vendor-extra/JatsContentBundle/src/ViewConverter/SectionVisitor.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,28 @@ public function __construct(ViewConverter $converter)
2727
$this->converter = $converter;
2828
}
2929

30-
protected function doVisit(Element $object, View $view, array &$context = []) : View
30+
protected function doVisit(Element $object, View $view) : View
3131
{
32-
$context['level'] = $context['level'] ?? 1;
32+
if ($view->hasContext('level')) {
33+
$view = $view->withContext(['level' => 1]);
34+
}
3335

3436
$heading = $object->ownerDocument->xpath()
3537
->firstOf('jats:title', $object);
3638

3739
if ($heading instanceof Element) {
3840
$view = $view->withArgument(
3941
'heading',
40-
$this->converter->convert($heading, '@LiberoPatterns/heading.html.twig', $context)->getArguments()
42+
$this->converter
43+
->convert($heading, '@LiberoPatterns/heading.html.twig', $view->getContext())
44+
->getArguments()
4145
);
4246
}
4347

4448
/** @var DOMNodeList|Element[] $children */
4549
$children = $object('*[not(local-name()="title" and namespace-uri()="http://jats.nlm.nih.gov")]');
4650

47-
$childContext = $context;
51+
$childContext = $view->getContext();
4852
$childContext['level']++;
4953

5054
return $view->withArgument(

0 commit comments

Comments
 (0)