Skip to content

Make Crud - Change field name appearance #544

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

Open
wants to merge 2 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DependencyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getMissingPackagesMessage(string $commandName, $message = null):
$message = sprintf(
"Missing package%s: %s, run:\n",
$packagesCount > 1 ? 's' : '',
$message ? $message : sprintf('to use the %s command', $commandName)
$message ?: sprintf('to use the %s command', $commandName)
);

if (!empty($packages)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/crud/templates/edit.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{{ include('<?= $route_name ?>/_form.html.twig', {'button_label': 'Update'}) }}

<a href="{{ path('<?= $route_name ?>_index') }}">back to list</a>
<a href="{{ path('<?= $route_name ?>_index') }}">Back to list</a>

{{ include('<?= $route_name ?>/_delete_form.html.twig') }}
{% endblock %}
15 changes: 10 additions & 5 deletions src/Resources/skeleton/crud/templates/index.tpl.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

use Symfony\Bundle\MakerBundle\Str;

?>
<?= $helper->getHeadPrintCode($entity_class_name.' index'); ?>

{% block body %}
Expand All @@ -7,9 +12,9 @@
<thead>
<tr>
<?php foreach ($entity_fields as $field): ?>
<th><?= ucfirst($field['fieldName']) ?></th>
<th><?= Str::asHumanWords($field['fieldName']) ?></th>
<?php endforeach; ?>
<th>actions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
Expand All @@ -19,13 +24,13 @@
<td>{{ <?= $helper->getEntityFieldPrintCode($entity_twig_var_singular, $field) ?> }}</td>
<?php endforeach; ?>
<td>
<a href="{{ path('<?= $route_name ?>_show', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}">show</a>
<a href="{{ path('<?= $route_name ?>_edit', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}">edit</a>
<a href="{{ path('<?= $route_name ?>_show', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}">Show</a>

Choose a reason for hiding this comment

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

I guess it's debatable whether or not these should be capitalized. Personally I see as headings and think they should have a capital letter, but as values (similar to bullet list) and don't give them a capital letter, unless it's a name or some such.

A quick search on Google reveals there's no universal standard for table cells. In my experience many values in cells are database values that could be wrongly interpreted when given a capital letter, therefore I suggest to not give them a capital letter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@weaverryan wdyt ?

<a href="{{ path('<?= $route_name ?>_edit', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}">Edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="<?= (count($entity_fields) + 1) ?>">no records found</td>
<td colspan="<?= (count($entity_fields) + 1) ?>">No records found</td>
</tr>
{% endfor %}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/crud/templates/new.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

{{ include('<?= $route_name ?>/_form.html.twig') }}

<a href="{{ path('<?= $route_name ?>_index') }}">back to list</a>
<a href="{{ path('<?= $route_name ?>_index') }}">Back to list</a>
{% endblock %}
11 changes: 8 additions & 3 deletions src/Resources/skeleton/crud/templates/show.tpl.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

use Symfony\Bundle\MakerBundle\Str;

?>
<?= $helper->getHeadPrintCode($entity_class_name) ?>

{% block body %}
Expand All @@ -7,16 +12,16 @@
<tbody>
<?php foreach ($entity_fields as $field): ?>
<tr>
<th><?= ucfirst($field['fieldName']) ?></th>
<th><?= Str::asHumanWords($field['fieldName']) ?></th>
<td>{{ <?= $helper->getEntityFieldPrintCode($entity_twig_var_singular, $field) ?> }}</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

<a href="{{ path('<?= $route_name ?>_index') }}">back to list</a>
<a href="{{ path('<?= $route_name ?>_index') }}">Back to list</a>

<a href="{{ path('<?= $route_name ?>_edit', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}">edit</a>
<a href="{{ path('<?= $route_name ?>_edit', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}">Edit</a>

{{ include('<?= $route_name ?>/_delete_form.html.twig') }}
{% endblock %}
2 changes: 1 addition & 1 deletion src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ public static function areClassesAlphabetical(string $class1, string $class2)

public static function asHumanWords(string $variableName): string
{
return implode(' ', preg_split('/(?=[A-Z])/', $variableName));
return ucfirst(trim(implode(' ', array_map('lcfirst', preg_split('/(?=[A-Z])/', $variableName)))));
}
}
16 changes: 16 additions & 0 deletions tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,20 @@ public function getShortClassNameCaseTests()
yield ['App\\Entity\\Foo', 'Foo'];
yield ['Foo', 'Foo'];
}

/**
* @dataProvider getAsHumanWordsTests
*/
public function testAsHumanWords(string $original, string $expected)
{
$this->assertSame($expected, Str::asHumanWords($original));
}

public function getAsHumanWordsTests()
{
yield ['myVar', 'My var'];
yield ['mySuperVar', 'My super var'];
yield ['Foo', 'Foo'];
yield ['foo', 'Foo'];
}
}
6 changes: 3 additions & 3 deletions tests/fixtures/MakeCrud/tests/GeneratedCrudControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testIndexAction()
$this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());
$this->assertStringContainsString('<td>Candy</td>', $client->getResponse()->getContent());

$editLink = $crawler->filter('a:contains("edit")')->eq(0)->link();
$editLink = $crawler->filter('a:contains("Edit")')->eq(0)->link();
$crawler = $client->click($editLink);
$this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent());
$this->assertStringContainsString('Edit SweetFood', $client->getResponse()->getContent());
Expand All @@ -47,7 +47,7 @@ public function testIndexAction()
$this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());
$this->assertStringContainsString('Candy edited', $client->getResponse()->getContent());

$showLink = $crawler->filter('a:contains("show")')->eq(0)->link();
$showLink = $crawler->filter('a:contains("Show")')->eq(0)->link();

$crawler = $client->click($showLink);
$this->assertTrue($client->getResponse()->isSuccessful());
Expand All @@ -63,6 +63,6 @@ public function testIndexAction()
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent());
$this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());
$this->assertStringContainsString('no records found', $client->getResponse()->getContent());
$this->assertStringContainsString('No records found', $client->getResponse()->getContent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testIndexAction()
$this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());
$this->assertStringContainsString('<td>Candy</td>', $client->getResponse()->getContent());

$editLink = $crawler->filter('a:contains("edit")')->eq(0)->link();
$editLink = $crawler->filter('a:contains("Edit")')->eq(0)->link();
$crawler = $client->click($editLink);
$this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent());
$this->assertStringContainsString('Edit SweetFood', $client->getResponse()->getContent());
Expand All @@ -47,7 +47,7 @@ public function testIndexAction()
$this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());
$this->assertStringContainsString('Candy edited', $client->getResponse()->getContent());

$showLink = $crawler->filter('a:contains("show")')->eq(0)->link();
$showLink = $crawler->filter('a:contains("Show")')->eq(0)->link();

$crawler = $client->click($showLink);
$this->assertTrue($client->getResponse()->isSuccessful());
Expand All @@ -63,6 +63,6 @@ public function testIndexAction()
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent());
$this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());
$this->assertStringContainsString('no records found', $client->getResponse()->getContent());
$this->assertStringContainsString('No records found', $client->getResponse()->getContent());
}
}