9 | + {% for msg in app.session.flashBag.get('success') %}
10 | +
11 | + {{ msg }}
12 | +
13 | + {% endfor %}
14 | +
15 | {% block body %}{% endblock %}
16 |
17 |
18 | diff --git a/src/AppBundle/Controller/Admin/GenusAdminController.php b/src/AppBundle/Controller/Admin/GenusAdminController.php
19 | index 39bed81..7a84ec0 100644
20 | --- a/src/AppBundle/Controller/Admin/GenusAdminController.php
21 | +++ b/src/AppBundle/Controller/Admin/GenusAdminController.php
22 | @@ -42,6 +42,8 @@ class GenusAdminController extends Controller
23 | $em->persist($genus);
24 | $em->flush();
25 |
26 | + $this->addFlash('success', 'Genus created!');
27 | +
28 | return $this->redirectToRoute('admin_genus_list');
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/_tuts/flex-don-t-auto-register-appbundle.diff:
--------------------------------------------------------------------------------
1 | diff --git a/config/services.yaml b/config/services.yaml
2 | index 23800b4..a10e5cb 100644
3 | --- a/config/services.yaml
4 | +++ b/config/services.yaml
5 | @@ -15,7 +15,7 @@ services:
6 | # this creates a service per class whose id is the fully-qualified class name
7 | App\:
8 | resource: '../src/*'
9 | - exclude: '../src/{Entity,Migrations,Tests}'
10 | + exclude: '../src/{Entity,Migrations,Tests,AppBundle}'
11 |
12 | # controllers are imported separately to make sure services can be injected
13 | # as action arguments even if you don't extend any base controller class
14 |
--------------------------------------------------------------------------------
/_tuts/form-adding-adder-set-owning-side.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 19f74ee..70285fc 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -184,6 +184,8 @@ class Genus
6 | }
7 |
8 | $this->genusScientists[] = $genusScientist;
9 | + // needed to update the owning side of the relationship!
10 | + $genusScientist->setGenus($this);
11 | }
12 |
13 | public function removeGenusScientist(GenusScientist $genusScientist)
14 |
--------------------------------------------------------------------------------
/_tuts/form-adding-cascade-persist-partial-adder.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 97978c0..19f74ee 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -74,7 +74,8 @@ class Genus
6 | * targetEntity="GenusScientist",
7 | * mappedBy="genus",
8 | * fetch="EXTRA_LAZY",
9 | - * orphanRemoval=true
10 | + * orphanRemoval=true,
11 | + * cascade={"persist"}
12 | * )
13 | */
14 | private $genusScientists;
15 | @@ -176,15 +177,13 @@ class Genus
16 | $this->slug = $slug;
17 | }
18 |
19 | - public function addGenusScientist(User $user)
20 | + public function addGenusScientist(GenusScientist $genusScientist)
21 | {
22 | - if ($this->genusScientists->contains($user)) {
23 | + if ($this->genusScientists->contains($genusScientist)) {
24 | return;
25 | }
26 |
27 | - $this->genusScientists[] = $user;
28 | - // not needed for persistence, just keeping both sides in sync
29 | - $user->addStudiedGenus($this);
30 | + $this->genusScientists[] = $genusScientist;
31 | }
32 |
33 | public function removeGenusScientist(GenusScientist $genusScientist)
34 |
--------------------------------------------------------------------------------
/_tuts/form-collection-allow-delete.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Form/GenusFormType.php b/src/AppBundle/Form/GenusFormType.php
2 | index 2e53d5a..3f7a96e 100644
3 | --- a/src/AppBundle/Form/GenusFormType.php
4 | +++ b/src/AppBundle/Form/GenusFormType.php
5 | @@ -45,7 +45,8 @@ class GenusFormType extends AbstractType
6 | 'html5' => false,
7 | ])
8 | ->add('genusScientists', CollectionType::class, [
9 | - 'entry_type' => GenusScientistEmbeddedForm::class
10 | + 'entry_type' => GenusScientistEmbeddedForm::class,
11 | + 'allow_delete' => true,
12 | ])
13 | ;
14 | }
15 |
--------------------------------------------------------------------------------
/_tuts/form-collection-by-reference-remover.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index ba5c87d..4359120 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -182,15 +182,15 @@ class Genus
6 | $user->addStudiedGenus($this);
7 | }
8 |
9 | - public function removeGenusScientist(User $user)
10 | + public function removeGenusScientist(GenusScientist $genusScientist)
11 | {
12 | - if (!$this->genusScientists->contains($user)) {
13 | + if (!$this->genusScientists->contains($genusScientist)) {
14 | return;
15 | }
16 |
17 | - $this->genusScientists->removeElement($user);
18 | - // not needed for persistence, just keeping both sides in sync
19 | - $user->removeStudiedGenus($this);
20 | + $this->genusScientists->removeElement($genusScientist);
21 | + // needed to update the owning side of the relationship!
22 | + $genusScientist->setGenus(null);
23 | }
24 |
25 | /**
26 | diff --git a/src/AppBundle/Form/GenusFormType.php b/src/AppBundle/Form/GenusFormType.php
27 | index 3f7a96e..8119e12 100644
28 | --- a/src/AppBundle/Form/GenusFormType.php
29 | +++ b/src/AppBundle/Form/GenusFormType.php
30 | @@ -47,6 +47,7 @@ class GenusFormType extends AbstractType
31 | ->add('genusScientists', CollectionType::class, [
32 | 'entry_type' => GenusScientistEmbeddedForm::class,
33 | 'allow_delete' => true,
34 | + 'by_reference' => false,
35 | ])
36 | ;
37 | }
38 |
--------------------------------------------------------------------------------
/_tuts/form-collection-orphanremoval.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 4359120..97978c0 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -70,7 +70,12 @@ class Genus
6 | private $notes;
7 |
8 | /**
9 | - * @ORM\OneToMany(targetEntity="GenusScientist", mappedBy="genus", fetch="EXTRA_LAZY")
10 | + * @ORM\OneToMany(
11 | + * targetEntity="GenusScientist",
12 | + * mappedBy="genus",
13 | + * fetch="EXTRA_LAZY",
14 | + * orphanRemoval=true
15 | + * )
16 | */
17 | private $genusScientists;
18 |
19 |
--------------------------------------------------------------------------------
/_tuts/form-collection-render-a-little-better.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index c88b8cd..13f8d8e 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -19,7 +19,15 @@
6 | }) }}
7 |
8 | {{ form_row(genusForm.firstDiscoveredAt) }}
9 | - {{ form_row(genusForm.genusScientists) }}
10 | +
11 | +
7 | {{- form_label(form) -}}
8 | {{- form_widget(form) -}}
9 | - {% if help %}
10 | + {% if help|default %}
11 |
{{ help }}
12 | {% endif %}
13 | {{- form_errors(form) -}}
14 |
--------------------------------------------------------------------------------
/_tuts/form-help-passing-and-dumping-help-var.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index 36abf17..d155797 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -5,6 +5,7 @@
6 |
7 | {{- form_label(form) -}}
8 | {{- form_widget(form) -}}
9 | + {{ dump() }}
10 | {{- form_errors(form) -}}
11 |
12 | {%- endblock form_row %}
13 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
14 | index f87a511..158df54 100644
15 | --- a/app/Resources/views/admin/genus/_form.html.twig
16 | +++ b/app/Resources/views/admin/genus/_form.html.twig
17 | @@ -14,7 +14,9 @@
18 | 'label': 'Number of Species'
19 | }) }}
20 | {{ form_row(genusForm.funFact) }}
21 | - {{ form_row(genusForm.isPublished) }}
22 | + {{ form_row(genusForm.isPublished, {
23 | + help: 'Should this genus be shown on the site?'
24 | + }) }}
25 | {{ form_row(genusForm.firstDiscoveredAt) }}
26 |
27 |
28 |
--------------------------------------------------------------------------------
/_tuts/form-help-printing-help-var.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index d155797..0701619 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -5,7 +5,9 @@
6 |
7 | {{- form_label(form) -}}
8 | {{- form_widget(form) -}}
9 | - {{ dump() }}
10 | + {% if help %}
11 | + {{ help }}
12 | + {% endif %}
13 | {{- form_errors(form) -}}
14 |
15 | {%- endblock form_row %}
16 |
--------------------------------------------------------------------------------
/_tuts/form-help-set-area-describedby-attr.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index 469eb19..406b577 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -4,9 +4,13 @@
6 | {% set showErrorIcon = (not compound or force_error|default(false)) and not valid %}
7 |
8 | {{- form_label(form) -}}
9 | + {% if help|default %}
10 | + {# set the aria-describedby attribute #}
11 | + {%- set attr = attr|merge({'aria-describedby': 'help-block-'~id }) -%}
12 | + {% endif %}
13 | {{- form_widget(form) -}}
14 | {% if help|default %}
15 | - {{ help }}
16 | + {{ help }}
17 | {% endif %}
18 | {{- form_errors(form) -}}
19 |
20 |
--------------------------------------------------------------------------------
/_tuts/form-rendering-back-again-to-form-row.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index 5b5f3ec..be28466 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -1,9 +1,7 @@
6 | {{ form_start(genusForm) }}
7 | {{ form_errors(genusForm) }}
8 |
9 | - {{ form_label(genusForm.name) }}
10 | - {{ form_widget(genusForm.name) }}
11 | - {{ form_errors(genusForm.name) }}
12 | + {{ form_row(genusForm.name) }}
13 |
14 | {{ form_row(genusForm.subFamily) }}
15 | {{ form_row(genusForm.speciesCount, {
16 |
--------------------------------------------------------------------------------
/_tuts/form-rendering-back-to-form-row.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index 1fd0f43..0e789bc 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -1,7 +1,14 @@
6 | {{ form_start(genusForm) }}
7 | {{ form_errors(genusForm) }}
8 |
9 | - {{ form_widget(genusForm) }}
10 | + {{ form_row(genusForm.name) }}
11 | + {{ form_row(genusForm.subFamily) }}
12 | + {{ form_row(genusForm.speciesCount, {
13 | + 'label': 'Number of Species'
14 | + }) }}
15 | + {{ form_row(genusForm.funFact) }}
16 | + {{ form_row(genusForm.isPublished) }}
17 | + {{ form_row(genusForm.firstDiscoveredAt) }}
18 |
19 |
20 | {{ form_end(genusForm) }}
21 |
--------------------------------------------------------------------------------
/_tuts/form-rendering-form-widget.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index eb849d8..1fd0f43 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -1 +1,7 @@
6 | -{{ form(genusForm) }}
7 | \ No newline at end of file
8 | +{{ form_start(genusForm) }}
9 | + {{ form_errors(genusForm) }}
10 | +
11 | + {{ form_widget(genusForm) }}
12 | +
13 | +
14 | +{{ form_end(genusForm) }}
15 |
--------------------------------------------------------------------------------
/_tuts/form-rendering-form.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index 7f49e54..eb849d8 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -1,12 +1 @@
6 | -{{ form_start(genusForm) }}
7 | - {{ form_row(genusForm.name) }}
8 | - {{ form_row(genusForm.subFamily) }}
9 | - {{ form_row(genusForm.speciesCount, {
10 | - 'label': 'Number of Species'
11 | - }) }}
12 | - {{ form_row(genusForm.funFact) }}
13 | - {{ form_row(genusForm.isPublished) }}
14 | - {{ form_row(genusForm.firstDiscoveredAt) }}
15 | -
16 | -
17 | -{{ form_end(genusForm) }}
18 | +{{ form(genusForm) }}
19 | \ No newline at end of file
20 |
--------------------------------------------------------------------------------
/_tuts/form-rendering-use-3-functions.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index 0e789bc..5b5f3ec 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -1,7 +1,10 @@
6 | {{ form_start(genusForm) }}
7 | {{ form_errors(genusForm) }}
8 |
9 | - {{ form_row(genusForm.name) }}
10 | + {{ form_label(genusForm.name) }}
11 | + {{ form_widget(genusForm.name) }}
12 | + {{ form_errors(genusForm.name) }}
13 | +
14 | {{ form_row(genusForm.subFamily) }}
15 | {{ form_row(genusForm.speciesCount, {
16 | 'label': 'Number of Species'
17 |
--------------------------------------------------------------------------------
/_tuts/form-theme-dump-vars.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index 97cbf07..7c7d421 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -1,4 +1,5 @@
6 | {% block form_row -%}
7 | + {{ dump() }}
8 |
9 | {{- form_label(form) -}}
10 | {{- form_widget(form) -}}
11 |
--------------------------------------------------------------------------------
/_tuts/form-theme-override-form-widget-simple.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index 49eff51..f8c2b68 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -9,3 +9,10 @@
6 | {{- form_errors(form) -}}
7 |
8 | {%- endblock form_row %}
9 | +
10 | +{% block form_widget_simple -%}
11 | + {% if type is not defined or type not in ['file', 'hidden'] %}
12 | + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%}
13 | + {% endif %}
14 | + {{- parent() -}}
15 | +{%- endblock form_widget_simple %}
16 |
--------------------------------------------------------------------------------
/_tuts/form-theme-properly-show-error-icon.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index f4b16f8..36abf17 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -5,16 +5,18 @@
6 |
7 | {{- form_label(form) -}}
8 | {{- form_widget(form) -}}
9 | - {% if showErrorIcon %}
10 | -
11 | - {% endif %}
12 | {{- form_errors(form) -}}
13 |
14 | {%- endblock form_row %}
15 |
16 | {% block form_widget_simple -%}
17 | + {% set showErrorIcon = false %}
18 | {% if type is not defined or type not in ['file', 'hidden'] %}
19 | -
20 | + {# show error icon for these types #}
21 | + {% set showErrorIcon = (not compound or force_error|default(false)) and not valid %}
22 | {% endif %}
23 | {{- parent() -}}
24 | + {% if showErrorIcon %}
25 | +
26 | + {% endif %}
27 | {%- endblock form_widget_simple %}
28 |
--------------------------------------------------------------------------------
/_tuts/form-theme-remove-duplicated-parent-logic.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index c648d18..f4b16f8 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -14,7 +14,7 @@
6 |
7 | {% block form_widget_simple -%}
8 | {% if type is not defined or type not in ['file', 'hidden'] %}
9 | - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%}
10 | +
11 | {% endif %}
12 | {{- parent() -}}
13 | {%- endblock form_widget_simple %}
14 |
--------------------------------------------------------------------------------
/_tuts/form-theme-set-error-icon.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index 7c7d421..49eff51 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -1,8 +1,11 @@
6 | {% block form_row -%}
7 | - {{ dump() }}
8 | -
9 | + {% set showErrorIcon = (not compound or force_error|default(false)) and not valid %}
10 | +
11 | {{- form_label(form) -}}
12 | {{- form_widget(form) -}}
13 | + {% if showErrorIcon %}
14 | +
15 | + {% endif %}
16 | {{- form_errors(form) -}}
17 |
18 | {%- endblock form_row %}
19 |
--------------------------------------------------------------------------------
/_tuts/form-theme-use-bootstrap3-as-parent.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/_formTheme.html.twig b/app/Resources/views/_formTheme.html.twig
2 | index f8c2b68..c648d18 100644
3 | --- a/app/Resources/views/_formTheme.html.twig
4 | +++ b/app/Resources/views/_formTheme.html.twig
5 | @@ -1,3 +1,5 @@
6 | +{% use "bootstrap_3_layout.html.twig" %}
7 | +
8 | {% block form_row -%}
9 | {% set showErrorIcon = (not compound or force_error|default(false)) and not valid %}
10 |
11 |
--------------------------------------------------------------------------------
/_tuts/form-vars-override-attr.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index d50dea4..edc0b4c 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -4,7 +4,11 @@
6 | {{ form_row(genusForm.name) }}
7 |
8 | {{ form_row(genusForm.subFamily, {
9 | - 'label': 'Taxonomic Subfamily'
10 | + 'label': 'Taxonomic Subfamily',
11 | + 'attr': {
12 | + 'class': 'foo',
13 | + 'disabled': 'disabled'
14 | + }
15 | }) }}
16 | {{ form_row(genusForm.speciesCount, {
17 | 'label': 'Number of Species'
18 |
--------------------------------------------------------------------------------
/_tuts/form-vars-override-label.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index be28466..d50dea4 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -3,7 +3,9 @@
6 |
7 | {{ form_row(genusForm.name) }}
8 |
9 | - {{ form_row(genusForm.subFamily) }}
10 | + {{ form_row(genusForm.subFamily, {
11 | + 'label': 'Taxonomic Subfamily'
12 | + }) }}
13 | {{ form_row(genusForm.speciesCount, {
14 | 'label': 'Number of Species'
15 | }) }}
16 |
--------------------------------------------------------------------------------
/_tuts/form-vars-override-placeholder-var.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index 01e3227..f87a511 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -8,7 +8,7 @@
6 | 'attr': {
7 | 'class': 'foo'
8 | },
9 | - 'disabled': 'disabled',
10 | + 'placeholder': 'Select a Subfamily'
11 | }) }}
12 | {{ form_row(genusForm.speciesCount, {
13 | 'label': 'Number of Species'
14 |
--------------------------------------------------------------------------------
/_tuts/form-vars-set-disabled-variable.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/admin/genus/_form.html.twig b/app/Resources/views/admin/genus/_form.html.twig
2 | index edc0b4c..01e3227 100644
3 | --- a/app/Resources/views/admin/genus/_form.html.twig
4 | +++ b/app/Resources/views/admin/genus/_form.html.twig
5 | @@ -6,9 +6,9 @@
6 | {{ form_row(genusForm.subFamily, {
7 | 'label': 'Taxonomic Subfamily',
8 | 'attr': {
9 | - 'class': 'foo',
10 | - 'disabled': 'disabled'
11 | - }
12 | + 'class': 'foo'
13 | + },
14 | + 'disabled': 'disabled',
15 | }) }}
16 | {{ form_row(genusForm.speciesCount, {
17 | 'label': 'Number of Species'
18 |
--------------------------------------------------------------------------------
/_tuts/genus-form-add-data-class.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Form/GenusFormType.php b/src/AppBundle/Form/GenusFormType.php
2 | index b909507..f939b71 100644
3 | --- a/src/AppBundle/Form/GenusFormType.php
4 | +++ b/src/AppBundle/Form/GenusFormType.php
5 | @@ -19,6 +19,8 @@ class GenusFormType extends AbstractType
6 |
7 | public function configureOptions(OptionsResolver $resolver)
8 | {
9 | -
10 | + $resolver->setDefaults([
11 | + 'data_class' => 'AppBundle\Entity\Genus'
12 | + ]);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/_tuts/genus-form-add-genus-getispublished.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index ee9cfe3..8080d6d 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -113,6 +113,11 @@ class Genus
6 | $this->isPublished = $isPublished;
7 | }
8 |
9 | + public function getIsPublished()
10 | + {
11 | + return $this->isPublished;
12 | + }
13 | +
14 | /**
15 | * @return ArrayCollection|GenusNote[]
16 | */
17 |
--------------------------------------------------------------------------------
/_tuts/genus-form-add-other-fields.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/SubFamily.php b/src/AppBundle/Entity/SubFamily.php
2 | index 6e852c1..576d957 100644
3 | --- a/src/AppBundle/Entity/SubFamily.php
4 | +++ b/src/AppBundle/Entity/SubFamily.php
5 | @@ -36,4 +36,9 @@ class SubFamily
6 | {
7 | $this->name = $name;
8 | }
9 | +
10 | + public function __toString()
11 | + {
12 | + return $this->getName();
13 | + }
14 | }
15 | diff --git a/src/AppBundle/Form/GenusFormType.php b/src/AppBundle/Form/GenusFormType.php
16 | index f939b71..2ab818e 100644
17 | --- a/src/AppBundle/Form/GenusFormType.php
18 | +++ b/src/AppBundle/Form/GenusFormType.php
19 | @@ -12,8 +12,11 @@ class GenusFormType extends AbstractType
20 | {
21 | $builder
22 | ->add('name')
23 | + ->add('subFamily')
24 | ->add('speciesCount')
25 | ->add('funFact')
26 | + ->add('isPublished')
27 | + ->add('firstDiscoveredAt')
28 | ;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/_tuts/genus-form-save-and-redirect.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/Admin/GenusAdminController.php b/src/AppBundle/Controller/Admin/GenusAdminController.php
2 | index 586e356..39bed81 100644
3 | --- a/src/AppBundle/Controller/Admin/GenusAdminController.php
4 | +++ b/src/AppBundle/Controller/Admin/GenusAdminController.php
5 | @@ -36,7 +36,13 @@ class GenusAdminController extends Controller
6 | // only handles data on POST
7 | $form->handleRequest($request);
8 | if ($form->isSubmitted() && $form->isValid()) {
9 | - dump($form->getData());die;
10 | + $genus = $form->getData();
11 | +
12 | + $em = $this->getDoctrine()->getManager();
13 | + $em->persist($genus);
14 | + $em->flush();
15 | +
16 | + return $this->redirectToRoute('admin_genus_list');
17 | }
18 |
19 | return $this->render('admin/genus/new.html.twig', [
20 |
--------------------------------------------------------------------------------
/_tuts/guard-set-last-username.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Security/LoginFormAuthenticator.php b/src/AppBundle/Security/LoginFormAuthenticator.php
2 | index ffa7c90..ddd44d0 100644
3 | --- a/src/AppBundle/Security/LoginFormAuthenticator.php
4 | +++ b/src/AppBundle/Security/LoginFormAuthenticator.php
5 | @@ -7,6 +7,7 @@ use Doctrine\ORM\EntityManager;
6 | use Symfony\Component\Form\FormFactoryInterface;
7 | use Symfony\Component\HttpFoundation\Request;
8 | use Symfony\Component\Routing\RouterInterface;
9 | +use Symfony\Component\Security\Core\Security;
10 | use Symfony\Component\Security\Core\User\UserInterface;
11 | use Symfony\Component\Security\Core\User\UserProviderInterface;
12 | use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
13 | @@ -36,6 +37,10 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
14 | $form->handleRequest($request);
15 |
16 | $data = $form->getData();
17 | + $request->getSession()->set(
18 | + Security::LAST_USERNAME,
19 | + $data['_username']
20 | + );
21 |
22 | return $data;
23 | }
24 |
--------------------------------------------------------------------------------
/_tuts/inverse-form-fixing-infinite-loop.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 7ca89ab..259f24a 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -185,6 +185,10 @@ class Genus
6 |
7 | public function removeGenusScientist(User $user)
8 | {
9 | + if (!$this->genusScientists->contains($user)) {
10 | + return;
11 | + }
12 | +
13 | $this->genusScientists->removeElement($user);
14 | // not needed for persistence, just keeping both sides in sync
15 | $user->removeStudiedGenus($this);
16 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
17 | index 50c2c9a..85f5458 100644
18 | --- a/src/AppBundle/Entity/User.php
19 | +++ b/src/AppBundle/Entity/User.php
20 | @@ -233,6 +233,10 @@ class User implements UserInterface
21 |
22 | public function removeStudiedGenus(Genus $genus)
23 | {
24 | + if (!$this->studiedGenuses->contains($genus)) {
25 | + return;
26 | + }
27 | +
28 | $this->studiedGenuses->removeElement($genus);
29 | $genus->removeGenusScientist($this);
30 | }
31 |
--------------------------------------------------------------------------------
/_tuts/inverse-form-set-owning-side.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
2 | index f45c1af..50c2c9a 100644
3 | --- a/src/AppBundle/Entity/User.php
4 | +++ b/src/AppBundle/Entity/User.php
5 | @@ -228,10 +228,12 @@ class User implements UserInterface
6 | }
7 |
8 | $this->studiedGenuses[] = $genus;
9 | + $genus->addGenusScientist($this);
10 | }
11 |
12 | public function removeStudiedGenus(Genus $genus)
13 | {
14 | $this->studiedGenuses->removeElement($genus);
15 | + $genus->removeGenusScientist($this);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/_tuts/inverse-form-sync-inverse-side.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 4965fc8..7ca89ab 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -179,11 +179,15 @@ class Genus
6 | }
7 |
8 | $this->genusScientists[] = $user;
9 | + // not needed for persistence, just keeping both sides in sync
10 | + $user->addStudiedGenus($this);
11 | }
12 |
13 | public function removeGenusScientist(User $user)
14 | {
15 | $this->genusScientists->removeElement($user);
16 | + // not needed for persistence, just keeping both sides in sync
17 | + $user->removeStudiedGenus($this);
18 | }
19 |
20 | /**
21 |
--------------------------------------------------------------------------------
/_tuts/inverse-form-use-by-reference.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
2 | index 6547e5f..f45c1af 100644
3 | --- a/src/AppBundle/Entity/User.php
4 | +++ b/src/AppBundle/Entity/User.php
5 | @@ -220,4 +220,18 @@ class User implements UserInterface
6 | {
7 | return $this->studiedGenuses;
8 | }
9 | +
10 | + public function addStudiedGenus(Genus $genus)
11 | + {
12 | + if ($this->studiedGenuses->contains($genus)) {
13 | + return;
14 | + }
15 | +
16 | + $this->studiedGenuses[] = $genus;
17 | + }
18 | +
19 | + public function removeStudiedGenus(Genus $genus)
20 | + {
21 | + $this->studiedGenuses->removeElement($genus);
22 | + }
23 | }
24 | diff --git a/src/AppBundle/Form/UserEditForm.php b/src/AppBundle/Form/UserEditForm.php
25 | index b40216e..b8f01eb 100644
26 | --- a/src/AppBundle/Form/UserEditForm.php
27 | +++ b/src/AppBundle/Form/UserEditForm.php
28 | @@ -27,6 +27,7 @@ class UserEditForm extends AbstractType
29 | 'multiple' => true,
30 | 'expanded' => true,
31 | 'choice_label' => 'name',
32 | + 'by_reference' => false,
33 | ])
34 | ;
35 | }
36 |
--------------------------------------------------------------------------------
/_tuts/join-entity-fix-migration.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/DoctrineMigrations/Version20161017160251.php b/app/DoctrineMigrations/Version20161017160251.php
2 | index 300b10a..8cb53b9 100644
3 | --- a/app/DoctrineMigrations/Version20161017160251.php
4 | +++ b/app/DoctrineMigrations/Version20161017160251.php
5 | @@ -21,10 +21,9 @@ class Version20161017160251 extends AbstractMigration
6 | $this->addSql('ALTER TABLE genus_scientist DROP FOREIGN KEY FK_66CF3FA885C4074C');
7 | $this->addSql('ALTER TABLE genus_scientist DROP FOREIGN KEY FK_66CF3FA8A76ED395');
8 | $this->addSql('ALTER TABLE genus_scientist DROP PRIMARY KEY');
9 | - $this->addSql('ALTER TABLE genus_scientist ADD id INT AUTO_INCREMENT NOT NULL, ADD years_studied VARCHAR(255) NOT NULL');
10 | + $this->addSql('ALTER TABLE genus_scientist ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id), ADD years_studied VARCHAR(255) NOT NULL');
11 | $this->addSql('ALTER TABLE genus_scientist ADD CONSTRAINT FK_66CF3FA885C4074C FOREIGN KEY (genus_id) REFERENCES genus (id)');
12 | $this->addSql('ALTER TABLE genus_scientist ADD CONSTRAINT FK_66CF3FA8A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
13 | - $this->addSql('ALTER TABLE genus_scientist ADD PRIMARY KEY (id)');
14 | }
15 |
16 | /**
17 |
--------------------------------------------------------------------------------
/_tuts/join-entity-unique-index.diff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/knpuniversity/symfony/e953f6e2210364789ac8e680040e5ccc588bd161/_tuts/join-entity-unique-index.diff
--------------------------------------------------------------------------------
/_tuts/join-entity-update-fixtures.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/DataFixtures/ORM/fixtures.yml b/src/AppBundle/DataFixtures/ORM/fixtures.yml
2 | index 22f9f40..12c2484 100644
3 | --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml
4 | +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml
5 | @@ -35,3 +35,9 @@ AppBundle\Entity\User:
6 | lastName:
7 | universityName: University
8 | avatarUri:
9 | +
10 | +AppBundle\Entity\GenusScientist:
11 | + genus.scientist_{1..50}:
12 | + user: '@user.aquanaut_*'
13 | + genus: '@genus_*'
14 | + yearsStudied:
15 |
--------------------------------------------------------------------------------
/_tuts/join-finish-query-on-relation.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Repository/GenusNoteRepository.php b/src/AppBundle/Repository/GenusNoteRepository.php
2 | index ae393f6..9bde0e5 100644
3 | --- a/src/AppBundle/Repository/GenusNoteRepository.php
4 | +++ b/src/AppBundle/Repository/GenusNoteRepository.php
5 | @@ -15,6 +15,11 @@ class GenusNoteRepository extends EntityRepository
6 | public function findAllRecentNotesForGenus(Genus $genus)
7 | {
8 | return $this->createQueryBuilder('genus_note')
9 | + ->andWhere('genus_note.genus = :genus')
10 | + ->setParameter('genus', $genus)
11 | + ->andWhere('genus_note.createdAt > :recentDate')
12 | + ->setParameter('recentDate', new \DateTime('-3 months'))
13 | + ->orderBy('genus_note.createdAt', 'DESC')
14 | ->getQuery()
15 | ->execute();
16 | }
17 |
--------------------------------------------------------------------------------
/_tuts/join-join-query-to-order-by-relation.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index 6f22a98..8f2c0e6 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -45,7 +45,7 @@ class GenusController extends Controller
6 | $em = $this->getDoctrine()->getManager();
7 |
8 | $genuses = $em->getRepository('AppBundle:Genus')
9 | - ->findAllPublishedOrderedBySize();
10 | + ->findAllPublishedOrderedByRecentlyActive();
11 |
12 | return $this->render('genus/list.html.twig', [
13 | 'genuses' => $genuses
14 | diff --git a/src/AppBundle/Repository/GenusRepository.php b/src/AppBundle/Repository/GenusRepository.php
15 | index e19fe35..ef4682c 100644
16 | --- a/src/AppBundle/Repository/GenusRepository.php
17 | +++ b/src/AppBundle/Repository/GenusRepository.php
18 | @@ -10,12 +10,13 @@ class GenusRepository extends EntityRepository
19 | /**
20 | * @return Genus[]
21 | */
22 | - public function findAllPublishedOrderedBySize()
23 | + public function findAllPublishedOrderedByRecentlyActive()
24 | {
25 | return $this->createQueryBuilder('genus')
26 | ->andWhere('genus.isPublished = :isPublished')
27 | ->setParameter('isPublished', true)
28 | - ->orderBy('genus.speciesCount', 'DESC')
29 | + ->leftJoin('genus.notes', 'genus_note')
30 | + ->orderBy('genus_note.createdAt', 'DESC')
31 | ->getQuery()
32 | ->execute();
33 | }
34 |
--------------------------------------------------------------------------------
/_tuts/join-lazy-filter-for-recent-notes.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/genus/show.html.twig b/app/Resources/views/genus/show.html.twig
2 | index 551fb1f..4b72686 100644
3 | --- a/app/Resources/views/genus/show.html.twig
4 | +++ b/app/Resources/views/genus/show.html.twig
5 | @@ -15,6 +15,8 @@
6 | {{ genus.speciesCount|number_format }}
7 | Fun Fact:
8 | {{ genus.funFact }}
9 | + Recent Notes
10 | + {{ recentNoteCount }}
11 |
12 |
13 |
14 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
15 | index 3baa538..0206043 100644
16 | --- a/src/AppBundle/Controller/GenusController.php
17 | +++ b/src/AppBundle/Controller/GenusController.php
18 | @@ -83,8 +83,14 @@ class GenusController extends Controller
19 | $this->get('logger')
20 | ->info('Showing genus: '.$genusName);
21 |
22 | + $recentNotes = $genus->getNotes()
23 | + ->filter(function(GenusNote $note) {
24 | + return $note->getCreatedAt() > new \DateTime('-3 months');
25 | + });
26 | +
27 | return $this->render('genus/show.html.twig', array(
28 | - 'genus' => $genus
29 | + 'genus' => $genus,
30 | + 'recentNoteCount' => count($recentNotes)
31 | ));
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/_tuts/json-pass-in-dynamic-uri.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/genus/show.html.twig b/app/Resources/views/genus/show.html.twig
2 | index 62b4c38..b011382 100644
3 | --- a/app/Resources/views/genus/show.html.twig
4 | +++ b/app/Resources/views/genus/show.html.twig
5 | @@ -29,8 +29,10 @@
6 |
7 |
8 |
17 | diff --git a/web/js/notes.react.js b/web/js/notes.react.js
18 | index 0735701..c88f934 100644
19 | --- a/web/js/notes.react.js
20 | +++ b/web/js/notes.react.js
21 | @@ -12,7 +12,7 @@ var NoteSection = React.createClass({
22 |
23 | loadNotesFromServer: function() {
24 | $.ajax({
25 | - url: '/genus/octopus/notes',
26 | + url: this.props.url,
27 | success: function (data) {
28 | this.setState({notes: data.notes});
29 | }.bind(this)
30 |
--------------------------------------------------------------------------------
/_tuts/json-use-jsonresponse.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index 585e549..a4a7ae6 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -5,6 +5,7 @@ namespace AppBundle\Controller;
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9 | +use Symfony\Component\HttpFoundation\JsonResponse;
10 | use Symfony\Component\HttpFoundation\Response;
11 |
12 | class GenusController extends Controller
13 | @@ -34,6 +35,6 @@ class GenusController extends Controller
14 | 'notes' => $notes
15 | ];
16 |
17 | - return new Response(json_encode($data));
18 | + return new JsonResponse($data);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/_tuts/link-add-route-name-and-link.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/genus/list.html.twig b/app/Resources/views/genus/list.html.twig
2 | index 9e7e36e..eb8b2c8 100644
3 | --- a/app/Resources/views/genus/list.html.twig
4 | +++ b/app/Resources/views/genus/list.html.twig
5 | @@ -12,7 +12,11 @@
6 |
7 | {% for genus in genuses %}
8 |
9 | - {{ genus.name }} |
10 | +
11 | +
12 | + {{ genus.name }}
13 | +
14 | + |
15 | {{ genus.speciesCount }} |
16 | {{ genus.updatedAt|date('Y-m-d') }} |
17 |
18 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
19 | index efd665c..32cb716 100644
20 | --- a/src/AppBundle/Controller/GenusController.php
21 | +++ b/src/AppBundle/Controller/GenusController.php
22 | @@ -44,7 +44,7 @@ class GenusController extends Controller
23 | }
24 |
25 | /**
26 | - * @Route("/genus/{genusName}")
27 | + * @Route("/genus/{genusName}", name="genus_show")
28 | */
29 | public function showAction($genusName)
30 | {
31 |
--------------------------------------------------------------------------------
/_tuts/login-form-blank-authenticator.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Security/LoginFormAuthenticator.php b/src/AppBundle/Security/LoginFormAuthenticator.php
2 | new file mode 100644
3 | index 0000000..b70a5ac
4 | --- /dev/null
5 | +++ b/src/AppBundle/Security/LoginFormAuthenticator.php
6 | @@ -0,0 +1,31 @@
7 | +formFactory = $formFactory;
23 | + }
24 | +
25 | public function getCredentials(Request $request)
26 | {
27 | + $isLoginSubmit = $request->getPathInfo() == '/login' && $request->isMethod('POST');
28 | + if (!$isLoginSubmit) {
29 | + // skip authentication
30 | + return;
31 | + }
32 | +
33 | + $form = $this->formFactory->create(LoginForm::class);
34 | + $form->handleRequest($request);
35 | +
36 | + $data = $form->getData();
37 | +
38 | + return $data;
39 | }
40 |
41 | public function getUser($credentials, UserProviderInterface $userProvider)
42 |
--------------------------------------------------------------------------------
/_tuts/login-form-getuser-authenticator.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Security/LoginFormAuthenticator.php b/src/AppBundle/Security/LoginFormAuthenticator.php
2 | index d93a069..57dbeea 100644
3 | --- a/src/AppBundle/Security/LoginFormAuthenticator.php
4 | +++ b/src/AppBundle/Security/LoginFormAuthenticator.php
5 | @@ -3,6 +3,7 @@
6 | namespace AppBundle\Security;
7 |
8 | use AppBundle\Form\LoginForm;
9 | +use Doctrine\ORM\EntityManager;
10 | use Symfony\Component\Form\FormFactoryInterface;
11 | use Symfony\Component\HttpFoundation\Request;
12 | use Symfony\Component\Security\Core\User\UserInterface;
13 | @@ -12,10 +13,12 @@ use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticato
14 | class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
15 | {
16 | private $formFactory;
17 | + private $em;
18 |
19 | - public function __construct(FormFactoryInterface $formFactory)
20 | + public function __construct(FormFactoryInterface $formFactory, EntityManager $em)
21 | {
22 | $this->formFactory = $formFactory;
23 | + $this->em = $em;
24 | }
25 |
26 | public function getCredentials(Request $request)
27 | @@ -36,6 +39,10 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
28 |
29 | public function getUser($credentials, UserProviderInterface $userProvider)
30 | {
31 | + $username = $credentials['_username'];
32 | +
33 | + return $this->em->getRepository('AppBundle:User')
34 | + ->findOneBy(['email' => $username]);
35 | }
36 |
37 | public function checkCredentials($credentials, UserInterface $user)
38 |
--------------------------------------------------------------------------------
/_tuts/login-form-start-controller.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/SecurityController.php b/src/AppBundle/Controller/SecurityController.php
2 | new file mode 100644
3 | index 0000000..d912c10
4 | --- /dev/null
5 | +++ b/src/AppBundle/Controller/SecurityController.php
6 | @@ -0,0 +1,16 @@
7 | +genusScientists[] = $user;
7 | }
8 |
9 | + /**
10 | + * @return ArrayCollection|User[]
11 | + */
12 | public function getGenusScientists()
13 | {
14 | return $this->genusScientists;
15 |
--------------------------------------------------------------------------------
/_tuts/manytomany-create-from-genus-to-user.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 0f42d6c..886a445 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -69,9 +69,15 @@ class Genus
6 | */
7 | private $notes;
8 |
9 | + /**
10 | + * @ORM\ManyToMany(targetEntity="User")
11 | + */
12 | + private $genusScientists;
13 | +
14 | public function __construct()
15 | {
16 | $this->notes = new ArrayCollection();
17 | + $this->genusScientists = new ArrayCollection();
18 | }
19 |
20 | public function getId()
21 |
--------------------------------------------------------------------------------
/_tuts/manytomany-manually-add-user-to-relation.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index ace2f64..c99e925 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -36,6 +36,10 @@ class GenusController extends Controller
6 | $genusNote->setCreatedAt(new \DateTime('-1 month'));
7 | $genusNote->setGenus($genus);
8 |
9 | + $user = $em->getRepository('AppBundle:User')
10 | + ->findOneBy(['email' => 'aquanaut1@example.org']);
11 | + $genus->addGenusScientist($user);
12 | +
13 | $em->persist($genus);
14 | $em->persist($genusNote);
15 | $em->flush();
16 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
17 | index 0e06a2c..07e1c25 100644
18 | --- a/src/AppBundle/Entity/Genus.php
19 | +++ b/src/AppBundle/Entity/Genus.php
20 | @@ -171,4 +171,9 @@ class Genus
21 | {
22 | $this->slug = $slug;
23 | }
24 | +
25 | + public function addGenusScientist(User $user)
26 | + {
27 | + $this->genusScientists[] = $user;
28 | + }
29 | }
30 |
--------------------------------------------------------------------------------
/_tuts/manytomany-prevent-duplicates.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index c99e925..9c743b2 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -39,6 +39,7 @@ class GenusController extends Controller
6 | $user = $em->getRepository('AppBundle:User')
7 | ->findOneBy(['email' => 'aquanaut1@example.org']);
8 | $genus->addGenusScientist($user);
9 | + $genus->addGenusScientist($user); // duplicate is ignored!
10 |
11 | $em->persist($genus);
12 | $em->persist($genusNote);
13 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
14 | index 07e1c25..51e5689 100644
15 | --- a/src/AppBundle/Entity/Genus.php
16 | +++ b/src/AppBundle/Entity/Genus.php
17 | @@ -174,6 +174,10 @@ class Genus
18 |
19 | public function addGenusScientist(User $user)
20 | {
21 | + if ($this->genusScientists->contains($user)) {
22 | + return;
23 | + }
24 | +
25 | $this->genusScientists[] = $user;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/_tuts/manytomany-use-collection-to-print.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/Resources/views/genus/show.html.twig b/app/Resources/views/genus/show.html.twig
2 | index ce74d08..217353e 100644
3 | --- a/app/Resources/views/genus/show.html.twig
4 | +++ b/app/Resources/views/genus/show.html.twig
5 | @@ -17,6 +17,21 @@
6 | {{ genus.funFact|markdownify }}
7 | Recent Notes
8 | {{ recentNoteCount }}
9 | +
10 | + Lead Scientists
11 | +
12 | +
23 | +
24 |
25 |
26 |
27 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
28 | index 51e5689..615c81b 100644
29 | --- a/src/AppBundle/Entity/Genus.php
30 | +++ b/src/AppBundle/Entity/Genus.php
31 | @@ -180,4 +180,9 @@ class Genus
32 |
33 | $this->genusScientists[] = $user;
34 | }
35 | +
36 | + public function getGenusScientists()
37 | + {
38 | + return $this->genusScientists;
39 | + }
40 | }
41 |
--------------------------------------------------------------------------------
/_tuts/manytomany-using-orderby.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
2 | index a40e075..6547e5f 100644
3 | --- a/src/AppBundle/Entity/User.php
4 | +++ b/src/AppBundle/Entity/User.php
5 | @@ -77,6 +77,7 @@ class User implements UserInterface
6 |
7 | /**
8 | * @ORM\ManyToMany(targetEntity="Genus", mappedBy="genusScientists")
9 | + * @ORM\OrderBy({"name" = "ASC"})
10 | */
11 | private $studiedGenuses;
12 |
13 |
--------------------------------------------------------------------------------
/_tuts/manytoone-fixtures-with-reference.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/DataFixtures/ORM/fixtures.yml b/src/AppBundle/DataFixtures/ORM/fixtures.yml
2 | index 57f8fe7..271735f 100644
3 | --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml
4 | +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml
5 | @@ -12,3 +12,4 @@ AppBundle\Entity\GenusNote:
6 | userAvatarFilename: '50%? leanna.jpeg : ryan.jpeg'
7 | note:
8 | createdAt:
9 | + genus: '@genus_*'
10 |
--------------------------------------------------------------------------------
/_tuts/manytoone-genusnote-fixtures.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/DataFixtures/ORM/fixtures.yml b/src/AppBundle/DataFixtures/ORM/fixtures.yml
2 | index 58e64d6..57f8fe7 100644
3 | --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml
4 | +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml
5 | @@ -5,3 +5,10 @@ AppBundle\Entity\Genus:
6 | speciesCount:
7 | funFact:
8 | isPublished:
9 | +
10 | +AppBundle\Entity\GenusNote:
11 | + genus.note_{1..100}:
12 | + username:
13 | + userAvatarFilename: '50%? leanna.jpeg : ryan.jpeg'
14 | + note:
15 | + createdAt:
16 |
--------------------------------------------------------------------------------
/_tuts/manytoone-setup-genusnote-genus-property.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/GenusNote.php b/src/AppBundle/Entity/GenusNote.php
2 | index 4434903..7dd0505 100644
3 | --- a/src/AppBundle/Entity/GenusNote.php
4 | +++ b/src/AppBundle/Entity/GenusNote.php
5 | @@ -37,6 +37,11 @@ class GenusNote
6 | */
7 | private $createdAt;
8 |
9 | + /**
10 | + * @ORM\ManyToOne(targetEntity="Genus")
11 | + */
12 | + private $genus;
13 | +
14 | public function getId()
15 | {
16 | return $this->id;
17 | @@ -81,4 +86,14 @@ class GenusNote
18 | {
19 | $this->createdAt = $createdAt;
20 | }
21 | +
22 | + public function getGenus()
23 | + {
24 | + return $this->genus;
25 | + }
26 | +
27 | + public function setGenus($genus)
28 | + {
29 | + $this->genus = $genus;
30 | + }
31 | }
32 |
--------------------------------------------------------------------------------
/_tuts/manytoone-type-hint-setter-for-clarity.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/GenusNote.php b/src/AppBundle/Entity/GenusNote.php
2 | index 7dd0505..69dffbf 100644
3 | --- a/src/AppBundle/Entity/GenusNote.php
4 | +++ b/src/AppBundle/Entity/GenusNote.php
5 | @@ -92,7 +92,7 @@ class GenusNote
6 | return $this->genus;
7 | }
8 |
9 | - public function setGenus($genus)
10 | + public function setGenus(Genus $genus)
11 | {
12 | $this->genus = $genus;
13 | }
14 |
--------------------------------------------------------------------------------
/_tuts/migrations-set-all-fields-but-funfact.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index 9c7b7c8..97acf4e 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -18,6 +18,8 @@ class GenusController extends Controller
6 | {
7 | $genus = new Genus();
8 | $genus->setName('Octopus'.rand(1, 100));
9 | + $genus->setSubFamily('Octopodinae');
10 | + $genus->setSpeciesCount(rand(100, 99999));
11 |
12 | $em = $this->getDoctrine()->getManager();
13 | $em->persist($genus);
14 |
--------------------------------------------------------------------------------
/_tuts/onetomany-basic-mapping.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index ad4b6c5..264b39a 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -2,6 +2,7 @@
6 |
7 | namespace AppBundle\Entity;
8 |
9 | +use Doctrine\Common\Collections\ArrayCollection;
10 | use Doctrine\ORM\Mapping as ORM;
11 |
12 | /**
13 | @@ -42,6 +43,16 @@ class Genus
14 | */
15 | private $isPublished = true;
16 |
17 | + /**
18 | + * @ORM\OneToMany(targetEntity="GenusNote", mappedBy="genus")
19 | + */
20 | + private $notes;
21 | +
22 | + public function __construct()
23 | + {
24 | + $this->notes = new ArrayCollection();
25 | + }
26 | +
27 | public function getName()
28 | {
29 | return $this->name;
30 | @@ -91,4 +102,9 @@ class Genus
31 | {
32 | $this->isPublished = $isPublished;
33 | }
34 | +
35 | + public function getNotes()
36 | + {
37 | + return $this->notes;
38 | + }
39 | }
40 | diff --git a/src/AppBundle/Entity/GenusNote.php b/src/AppBundle/Entity/GenusNote.php
41 | index 84b4774..8f35521 100644
42 | --- a/src/AppBundle/Entity/GenusNote.php
43 | +++ b/src/AppBundle/Entity/GenusNote.php
44 | @@ -38,7 +38,7 @@ class GenusNote
45 | private $createdAt;
46 |
47 | /**
48 | - * @ORM\ManyToOne(targetEntity="Genus")
49 | + * @ORM\ManyToOne(targetEntity="Genus", inversedBy="notes")
50 | * @ORM\JoinColumn(nullable=false)
51 | */
52 | private $genus;
53 |
--------------------------------------------------------------------------------
/_tuts/onetomany-begin-to-build-notes-array.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index dad29b0..db5f705 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -94,9 +94,14 @@ class GenusController extends Controller
6 | */
7 | public function getNotesAction(Genus $genus)
8 | {
9 | + $notes = [];
10 | +
11 | foreach ($genus->getNotes() as $note) {
12 | - dump($note);
13 | + $notes[] = [
14 | + 'id' => $note->getId(),
15 | + ];
16 | }
17 | +
18 | $notes = [
19 | ['id' => 1, 'username' => 'AquaPelham', 'avatarUri' => '/images/leanna.jpeg', 'note' => 'Octopus asked me a riddle, outsmarted me', 'date' => 'Dec. 10, 2015'],
20 | ['id' => 2, 'username' => 'AquaWeaver', 'avatarUri' => '/images/ryan.jpeg', 'note' => 'I counted 8 legs... as they wrapped around me', 'date' => 'Dec. 1, 2015'],
21 |
--------------------------------------------------------------------------------
/_tuts/onetomany-looping-over-relation.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Controller/GenusController.php b/src/AppBundle/Controller/GenusController.php
2 | index ca1d67d..dad29b0 100644
3 | --- a/src/AppBundle/Controller/GenusController.php
4 | +++ b/src/AppBundle/Controller/GenusController.php
5 | @@ -94,7 +94,9 @@ class GenusController extends Controller
6 | */
7 | public function getNotesAction(Genus $genus)
8 | {
9 | - dump($genus);
10 | + foreach ($genus->getNotes() as $note) {
11 | + dump($note);
12 | + }
13 | $notes = [
14 | ['id' => 1, 'username' => 'AquaPelham', 'avatarUri' => '/images/leanna.jpeg', 'note' => 'Octopus asked me a riddle, outsmarted me', 'date' => 'Dec. 10, 2015'],
15 | ['id' => 2, 'username' => 'AquaWeaver', 'avatarUri' => '/images/ryan.jpeg', 'note' => 'I counted 8 legs... as they wrapped around me', 'date' => 'Dec. 1, 2015'],
16 |
--------------------------------------------------------------------------------
/_tuts/onetomany-order-by-on-relation.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/Genus.php b/src/AppBundle/Entity/Genus.php
2 | index 7bafd19..ca2cd9e 100644
3 | --- a/src/AppBundle/Entity/Genus.php
4 | +++ b/src/AppBundle/Entity/Genus.php
5 | @@ -45,6 +45,7 @@ class Genus
6 |
7 | /**
8 | * @ORM\OneToMany(targetEntity="GenusNote", mappedBy="genus")
9 | + * @ORM\OrderBy({"createdAt" = "DESC"})
10 | */
11 | private $notes;
12 |
13 |
--------------------------------------------------------------------------------
/_tuts/parameters-define-cache-type.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/config/config.yml b/app/config/config.yml
2 | index 4698dc3..a337277 100644
3 | --- a/app/config/config.yml
4 | +++ b/app/config/config.yml
5 | @@ -7,6 +7,7 @@ imports:
6 | # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
7 | parameters:
8 | locale: en
9 | + cache_type: file_system
10 |
11 | framework:
12 | #esi: ~
13 | @@ -73,6 +74,6 @@ swiftmailer:
14 | doctrine_cache:
15 | providers:
16 | my_markdown_cache:
17 | - type: file_system
18 | + type: %cache_type%
19 | file_system:
20 | directory: /tmp/doctrine_cache
21 |
--------------------------------------------------------------------------------
/_tuts/parameters-override-in-config-dev-yml.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml
2 | index b1b22be..09dc7b3 100644
3 | --- a/app/config/config_dev.yml
4 | +++ b/app/config/config_dev.yml
5 | @@ -1,6 +1,9 @@
6 | imports:
7 | - { resource: config.yml }
8 |
9 | +parameters:
10 | + cache_type: array
11 | +
12 | framework:
13 | router:
14 | resource: "%kernel.root_dir%/config/routing_dev.yml"
15 | @@ -43,8 +46,3 @@ monolog:
16 |
17 | #swiftmailer:
18 | # delivery_address: me@example.com
19 | -
20 | -doctrine_cache:
21 | - providers:
22 | - my_markdown_cache:
23 | - type: array
24 |
--------------------------------------------------------------------------------
/_tuts/parameters-use-built-in.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/config/config.yml b/app/config/config.yml
2 | index a337277..e4cec87 100644
3 | --- a/app/config/config.yml
4 | +++ b/app/config/config.yml
5 | @@ -76,4 +76,4 @@ doctrine_cache:
6 | my_markdown_cache:
7 | type: %cache_type%
8 | file_system:
9 | - directory: /tmp/doctrine_cache
10 | + directory: %kernel.cache_dir%/markdown_cache
11 |
--------------------------------------------------------------------------------
/_tuts/password-adding-plainpassword.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
2 | index cda6096..bbb2988 100644
3 | --- a/src/AppBundle/Entity/User.php
4 | +++ b/src/AppBundle/Entity/User.php
5 | @@ -31,6 +31,13 @@ class User implements UserInterface
6 | */
7 | private $password;
8 |
9 | + /**
10 | + * A non-persisted field that's used to create the encoded password.
11 | + *
12 | + * @var string
13 | + */
14 | + private $plainPassword;
15 | +
16 | // needed by the security system
17 | public function getUsername()
18 | {
19 | @@ -71,4 +78,14 @@ class User implements UserInterface
20 | {
21 | $this->password = $password;
22 | }
23 | +
24 | + public function getPlainPassword()
25 | + {
26 | + return $this->plainPassword;
27 | + }
28 | +
29 | + public function setPlainPassword($plainPassword)
30 | + {
31 | + $this->plainPassword = $plainPassword;
32 | + }
33 | }
34 |
--------------------------------------------------------------------------------
/_tuts/password-complete-prepersist.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Doctrine/HashPasswordListener.php b/src/AppBundle/Doctrine/HashPasswordListener.php
2 | index 43228c5..49a15b8 100644
3 | --- a/src/AppBundle/Doctrine/HashPasswordListener.php
4 | +++ b/src/AppBundle/Doctrine/HashPasswordListener.php
5 | @@ -2,11 +2,34 @@
6 |
7 | namespace AppBundle\Doctrine;
8 |
9 | +use AppBundle\Entity\User;
10 | use Doctrine\Common\EventSubscriber;
11 | use Doctrine\ORM\Event\LifecycleEventArgs;
12 | +use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
13 |
14 | class HashPasswordListener implements EventSubscriber
15 | {
16 | + private $passwordEncoder;
17 | +
18 | + public function __construct(UserPasswordEncoder $passwordEncoder)
19 | + {
20 | + $this->passwordEncoder = $passwordEncoder;
21 | + }
22 | +
23 | + public function prePersist(LifecycleEventArgs $args)
24 | + {
25 | + $entity = $args->getEntity();
26 | + if (!$entity instanceof User) {
27 | + return;
28 | + }
29 | +
30 | + $encoded = $this->passwordEncoder->encodePassword(
31 | + $entity,
32 | + $entity->getPlainPassword()
33 | + );
34 | + $entity->setPassword($encoded);
35 | + }
36 | +
37 | public function getSubscribedEvents()
38 | {
39 | return ['prePersist', 'preUpdate'];
40 |
--------------------------------------------------------------------------------
/_tuts/password-encoders-in-security-yml.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/config/security.yml b/app/config/security.yml
2 | index e3d26f0..3842e01 100644
3 | --- a/app/config/security.yml
4 | +++ b/app/config/security.yml
5 | @@ -1,6 +1,8 @@
6 | # To get started with security, check out the documentation:
7 | # http://symfony.com/doc/current/book/security.html
8 | security:
9 | + encoders:
10 | + AppBundle\Entity\User: bcrypt
11 |
12 | # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
13 | providers:
14 |
--------------------------------------------------------------------------------
/_tuts/password-erasecredentials.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
2 | index 31672b9..25c56da 100644
3 | --- a/src/AppBundle/Entity/User.php
4 | +++ b/src/AppBundle/Entity/User.php
5 | @@ -61,7 +61,7 @@ class User implements UserInterface
6 |
7 | public function eraseCredentials()
8 | {
9 | - // leaving blank - I don't need/have a password!
10 | + $this->plainPassword = null;
11 | }
12 |
13 | public function getEmail()
14 |
--------------------------------------------------------------------------------
/_tuts/password-force-dirty-mark.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
2 | index bbb2988..31672b9 100644
3 | --- a/src/AppBundle/Entity/User.php
4 | +++ b/src/AppBundle/Entity/User.php
5 | @@ -87,5 +87,8 @@ class User implements UserInterface
6 | public function setPlainPassword($plainPassword)
7 | {
8 | $this->plainPassword = $plainPassword;
9 | + // forces the object to look "dirty" to Doctrine. Avoids
10 | + // Doctrine *not* saving this entity, if only plainPassword changes
11 | + $this->password = null;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/_tuts/password-register-listener.diff:
--------------------------------------------------------------------------------
1 | diff --git a/app/config/services.yml b/app/config/services.yml
2 | index 11d2cd1..2587e60 100644
3 | --- a/app/config/services.yml
4 | +++ b/app/config/services.yml
5 | @@ -18,3 +18,9 @@ services:
6 | app.security.login_form_authenticator:
7 | class: AppBundle\Security\LoginFormAuthenticator
8 | autowire: true
9 | +
10 | + app.doctrine.hash_password_listener:
11 | + class: AppBundle\Doctrine\HashPasswordListener
12 | + autowire: true
13 | + tags:
14 | + - { name: doctrine.event_subscriber }
15 | diff --git a/src/AppBundle/DataFixtures/ORM/fixtures.yml b/src/AppBundle/DataFixtures/ORM/fixtures.yml
16 | index a035a98..21f9dec 100644
17 | --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml
18 | +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml
19 | @@ -23,3 +23,4 @@ AppBundle\Entity\SubFamily:
20 | AppBundle\Entity\User:
21 | user_{1..10}:
22 | email: weaverryan+@gmail.com
23 | + plainPassword: iliketurtles
24 |
--------------------------------------------------------------------------------
/_tuts/password-start-doctrine-listener.diff:
--------------------------------------------------------------------------------
1 | diff --git a/src/AppBundle/Doctrine/HashPasswordListener.php b/src/AppBundle/Doctrine/HashPasswordListener.php
2 | new file mode 100644
3 | index 0000000..43228c5
4 | --- /dev/null
5 | +++ b/src/AppBundle/Doctrine/HashPasswordListener.php
6 | @@ -0,0 +1,14 @@
7 | +Genus created!