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

fix incorrect generator of title for crud update view #383

Merged

Conversation

bscheshirwork
Copy link
Contributor

@bscheshirwork bscheshirwork commented Oct 24, 2018

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes
Fixed issues #382

Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

Need a line for changelog.

@samdark samdark added the type:bug Bug label Oct 26, 2018
@bscheshirwork bscheshirwork mentioned this pull request Nov 6, 2018
@bscheshirwork
Copy link
Contributor Author

#363

@samdark
Copy link
Member

samdark commented Nov 10, 2018

@bscheshirwork please add a line to CHANGELOG.

@samdark samdark merged commit 26faa5c into yiisoft:master Nov 12, 2018
@samdark
Copy link
Member

samdark commented Nov 12, 2018

Merged. Thank you!

@samdark samdark added this to the 2.0.8 milestone Nov 12, 2018
@bscheshirwork bscheshirwork deleted the fix-incorrect-generator-of-title branch November 13, 2018 07:35
@ricpelo
Copy link
Contributor

ricpelo commented Nov 22, 2018

This PR seems to bring #328 to life again 😢 .

@bscheshirwork
Copy link
Contributor Author

@ricpelo $generator->getNameAttribute() must return 'id' in your case?

@ricpelo
Copy link
Contributor

ricpelo commented Nov 22, 2018

That's right. As you can see in #328, the problem is that update.php incorrectly contains 'Update Socios: {nameAttribute}' instead of 'Update Socios: ' . $model->id. It was a problem I solved almost a year ago using PR #329, but with the latest changes it's now unfixed again.

@ricpelo
Copy link
Contributor

ricpelo commented Nov 22, 2018

PR #387 re-fix #328 in the same way as before.

@bscheshirwork
Copy link
Contributor Author

Look like incorrect work of $generator->getNameAttribute() without 'name' attribute

@ricpelo
Copy link
Contributor

ricpelo commented Nov 23, 2018

@bscheshirwork Just tested, and my PR #387 works OK on every case, with & without 'name' attribute, and with & without i18n. These are the generated code on every case:

With 'name' attribute, no i18n:

$this->title = 'Update Generos: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Generos', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';

With 'name' attribute and i18n:

$this->title = Yii::t('app', 'Update Generos: {name}', [
    'name' => '' . $model->name,
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Generos'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Update');

Without 'name' attribute, no i18n:

$this->title = 'Update Generos: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Generos', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';

Without 'name' attribute, with i18n:

$this->title = Yii::t('app', 'Update Generos: {name}', [
    'name' => '' . $model->id,
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Generos'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Update');

@ricpelo
Copy link
Contributor

ricpelo commented Nov 23, 2018

I've updated PR #387 to avoid unnecessary '' . concatenation which appears in the generated code when i18n enabled, so now the generated code looks even better:

With 'name' attribute, no i18n:

$this->title = 'Update Generos: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Generos', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';

With 'name' attribute and i18n:

$this->title = Yii::t('app', 'Update Generos: {name}', [
    'name' => $model->name,
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Generos'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Update');

Without 'name' attribute, no i18n:

$this->title = 'Update Generos: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Generos', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';

Without 'name' attribute, with i18n:

$this->title = Yii::t('app', 'Update Generos: {name}', [
    'name' => $model->id,
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Generos'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Update');

@ricpelo
Copy link
Contributor

ricpelo commented Nov 23, 2018

@bscheshirwork $generator->getNameAttribute() works OK, with & without 'name' attribute:

  • With 'name' attribute, it returns name.
  • Without 'name' attribute, it returns id.

The problem is in bad usage of the strtr() function in src/generators/crud/default/views/update.php file when used without i18n. My PR #387 fixes that.

samdark pushed a commit that referenced this pull request Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants