-
Notifications
You must be signed in to change notification settings - Fork 638
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
Title from related entry field should bubble up #4579
Comments
I’m not able to reproduce this; the title is continually updated as I change the value of the Entries field. Can you send your |
@brandonkelly Have you tried changing the value of the related entry field's title? My issue is specific to fields of a related entry. Not fields of the actual entry. Will email support with screen capture as well. Thanx. |
Sorry I had missed the word “title” in step 3; I only tested changing the actual related entry selection. I’m able to reproduce when editing an entry draft, if no additional changes are then made to the draft. Note that in Craft 3.2.3, entries are now immediately savable, whether or not Craft thinks you’ve made any changes (#4535). So even if Craft doesn’t pick up the title change right away, you can still click Save Entry, which will update the entry’s title. |
Yes if I force save the main entry A the title change from related entry B is picked up. But I would expect not having to go to entry A and force save it if related entry B is updated on its own or by another member of the team. Would you agree? |
Just looked into fixing this but unfortunately because the value of the field doesn’t change, there’s no clear indication that the draft needs to be updated after changing a related entry’s title. I don’t really want to force-resave the draft, since the chances are low that it will actually matter, and especially now that the lack of change detection won’t prevent you from saving the entry (which will definitely update the title), I think this is safe to close. The only awkwardness is that the draft’s title won’t update until you make another change. But if this is all you’re changing, you wouldn’t even be creating a draft to begin with in 3.2.3+. |
True, my only remaining concern is as I said earlier, if the related entry B gets updated on its own by another member of the team. Would I need to know that and act on entry A to reflect the change? Couldn't saving entry B actually 'reverse' update the title for entry A? Or is this not possible? Not sure I'm making myself clear here. |
Sorry that’s not possible; Craft isn’t really aware of Entry A’s dependency on Entry B for its Title Format. |
Ok I get that. Guess I could write a cron to periodically force save all entries A so that I'm sure it always reflect the correct title from related entry B. Thanx for your valued input Brandon, as always. Best. |
You could also set it up with a module: use craft\elements\Entry;
use craft\events\ModelEvent;
use craft\helpers\ElementHelper;
use yii\base\Event;
Event::on(Entry::class, Entry::EVENT_AFTER_SAVE, function(ModelEvent $e) {
/** @var Entry $entry */
$entry = $e->sender;
// Was this entry in Section B, and not a draft/revision/resave/site propagation?
if (
!ElementHelper::isDraftOrRevision($entry) &&
!$entry->propagating &&
!$entry->resaving &&
$entry->section->handle === 'section-b'
) {
// Resave all related entries from Section A
$relatedEntryQuery = Entry::find()
->section('section-a')
->relatedTo(['targetElement' => $entry, 'field' => 'myEntriesFieldHandle']);
Craft::$app->elements->resaveElements($relatedEntryQuery);
}
}); |
That's awesome! Still so much stuff to learn ;) |
Description
It is really nice that you can define your own Title in an entry as
{myOtherField}
.But it falls apart when we try using a related entry, as in
{myRelatedEntry.one().title}
. When changing that related entry title, it doesn't update the main entry title as would be expected.Steps to reproduce
myRelatedEntry
{myRelatedEntry.one().title}
Additional info
The text was updated successfully, but these errors were encountered: