Be sure to checkout our newest add-on Reading Time Pro!

EE4 compatibility updates:

  • Publisher is EE4 and EE5 compatible, but it does not currently support the Fluid field (it's in the works).
  • Reel is EE4 and EE5 compatible, but it does not currently support the Fluid field.

Ticket: Categories not parsed in front end and translation status columns are not displaying properly

Status Resolved
Add-on / Version Publisher 2.10.5
Severity
EE Version 4.3.7

Hop Studios

Jan 10, 2019

Hello Brian,

I am having problems with custom category fields post EE4 upgrade.

There is a category Resources (id: 288) that has a custom field called cat_navigation (all custom fields are not working I’m just using this one as example)
https://staging.lucistrust.org/testing
When I go to the EE native category page, none of the custom fields are displaying. I suspect ‘custom_field_modify_data’ has something to do with this.

The second issue is the one you helped addressed in the other ticket. The Translation status is now showing but the statuses. I am attaching a screenshot to show the before and after.

#1

BoldMinded (Brian)

Jan 11, 2019

Comment has been marked private.

#2

BoldMinded (Brian)

Jan 11, 2019

As for the translation statuses, those were updated in Publisher 2.something to be more accurate. It won’t show that the translation is complete until all the custom fields have a value assigned to them.

#3

Hop Studios

Jan 11, 2019

Yes that’s the weird part.

After I ran

UPDATE exp_extensions SET enabled='n' WHERE class="Publisher_ext" AND hook="custom_field_modify_data";

The data will show in https://staging.lucistrust.org/admin.php?/cp/categories/edit/2/288 but not https://staging.lucistrust.org/admin.php?/cp/addons/settings/publisher/manage/categories/translations/288
So the data is definitely there, but maybe during the update the conversion wasn’t done right (I don’t know how much the data structure has changed in terms of how Publisher deal with category fields)

My update process was
Publisher in 1.7.5 already
Playa Matrix importer
Update to EE3 (the category fields were already not displaying, | thought it was an EE native issue so I continued)
Update to EE4 (the category fields were still not showing any data)

#4

BoldMinded (Brian)

Jan 11, 2019

The custom_field_modify_data hook isn’t used for categories, its only used in channel entry fields.

#5

Hop Studios

Jan 11, 2019

That’s what I thought judging by the hook name but setting the extension to be disabled make the saved data appear: https://staging.lucistrust.org/admin.php?/cp/categories/edit/2/288

#6

BoldMinded (Brian)

Jan 11, 2019

Not sure how that is happening b/c I load up a category edit page locally and the hook isn’t getting called at all.

/cp/categories/edit/2/288 isn’t a Publisher page, and Publisher doesn’t try to modify anything on that page, it’s irrelevant to Publisher. Publisher manages translations at /cp/addons/settings/publisher/manage/categories/translations/288

#7

Hop Studios

Jan 11, 2019

Hello Brian,

It is the Show content fallback (CP). When it’s disabled, the EE native category edit page doesn’t show the category field data (same on my fresh installation)
https://staging.lucistrust.org/admin.php?/cp/addons/settings/publisher/general/display
And I discovered that Show content fallback (FE) doesn’t work for cataegory
Observe the last line (New category field:):
https://staging.lucistrust.org/testing
https://staging.lucistrust.org/fr/testing

1. Can you please let me know the Publisher 2’s category database structure? I think I need to port the legacy category fields into the new structure because it is just not working atm.
2. Can you let me know which files decide if the translation status should be lit for category fields? I’d like to make it so that only the required category fields matter.
3. Can you investigate in your fresh install to see if you can recreate the following error(bug)?
Step 1, Create 2 category groups
Step 2, Create a category field in each category group
Step 3, Create a category in each category group
Step 4, Go to the publisher category and select either category and hit edit
Step 5, See if both category fields show up even though they were created in different category group

Thanks!

#8

BoldMinded (Brian)

Jan 11, 2019

#1 - publisher_categories contains all the translations, and the custom field values are all in a JSON object in the custom_fields column of that table, and publisher_category_posts is where the cat to entry assignments are saved, just like the native category_posts table.

I’ll look into the rest of your last comment sometime over the weekend.

#9

BoldMinded (Brian)

Jan 12, 2019

#2 - In order for a translation to be complete, which changes those language status icons/pips to green, every category field (title, desc, image, and custom fields) must have a value.

#3 - I can replicate this. Yes it looks like all custom category fields are showing when editing a category, regardless of the group it is in. I’ll look into fixing this.

#10

BoldMinded (Brian)

Jan 13, 2019

Comment has been marked private.

#11

Hop Studios

Jan 14, 2019

Comment has been marked private.

#12

BoldMinded (Brian)

Jan 15, 2019

I’ll take a look at that new issue in a couple days… traveling for work this week.

2. No longer an issue, I put in some small modifications that suit the client’s need (only fade the status when no custom fields are entered or any required fields are not entered)

What sort of changes did you make? Would you mind sharing?

#13

BoldMinded (Brian)

Jan 15, 2019

Just looked into the category issue you described with the screenshot and was not able to replicate. Would you be able to attach a video of you re-creating the issue to make sure I’m following the steps exactly?

#14

Hop Studios

Jan 15, 2019

Hello Brian,

I will share the code when this last bit of issues are cleared so everything is clear.

I’ve attached the screencast. Please let me know if it’s not clear.

#15

BoldMinded (Brian)

Jan 16, 2019

I don’t see a screencast. Did you forget to paste the url? 😊

#16

Hop Studios

Jan 16, 2019

Comment has been marked private.

#17

BoldMinded (Brian)

Jan 16, 2019

I took the same steps you did as shown in the video and was not able to replicate. I tried logging into your CP to see the Publisher settings, but the login isn’t working.

I haven’t seen this happen before and it feels like something is up with your environment, otherwise I’d be able to replicate or would have probably gotten a similar report already b/c this code has not changed for quite awhile. Line 354 of Controllers/Manage/Categories.php is where the save is initiated, it seems like something in the foreach loops is missing, thus causing it to insert an empty row, almost like the page contains extra form fields with null values, which are added to the foreach loop. Are you able to debug those lines of code to make sure $languageId, $status, $groupId etc are all set before it tries to call ->save()?

#18

Hop Studios

Jan 23, 2019

Hello Brian,

Sorry for the late reply.
Can you please let me know what this code block is doing?

// Controllers/Manage/Categories.php line ~ 389
$categoryTranslation
    ->setCatId($categoryId)
    ->setGroupId($category->getGroupId())
    ->setLangId($languageId)
    ->setStatus($status)
    ->setEditDate(ee()->localize->now)
    ->setEditBy(ee()->session->userdata('member_id'))
    ->setIsAuto(null)
    ->save();

$category->Translations->add($categoryTranslation);
$category->save();

If I comment out the last 2 lines, the translations are saved correctly and no Null rows are created.
If those 2 lines are necessary, can you please let me know which files I can investigate the issues further?

Your CP access should be restored.

#19

BoldMinded (Brian)

Jan 23, 2019

Each $categoryTranslation is contains the translation data for the category, 1 per language on the site. $category is the main category data, and ->add is adding the translations to the category object. Commenting out those last 2 lines means the translations are not properly being assigned to the category, e.g. the database relationship ids.

#20

Hop Studios

Jan 24, 2019

So

$categoryTranslation
    ->setCatId($categoryId)
    ->setGroupId($category->getGroupId())
    ->setLangId($languageId)
    ->setStatus($status)
    ->setEditDate(ee()->localize->now)
    ->setEditBy(ee()->session->userdata('member_id'))
    ->setIsAuto(null)
    ->save();

Insert/Update records in exp_publisher_categories?

What table do these lines insert to?

$category->Translations->add($categoryTranslation);
$category->save();

What files are involved here? I think it’s probably with the site’s setup but it’d be easier to debug this way.

I put an echo after the $category->save(); and saw 16 rows of output (which is correct as we have 8 languages x 2 statuses). However, exp_publisher_categories got 32 rows inserted.

#21

BoldMinded (Brian)

Jan 24, 2019

publisher_categories and publisher_category_posts are the only Publisher related category tables. I miss-spoke about the database relationships, b/c its all added to exp_publisher_categories when saved. Were the empty/duplicate rows created when you had some of the code commented out?

#22

Hop Studios

Jan 24, 2019

Actually the opposite.

When I commented out the last 3 rows. I get 16 rows inserted into exp_publisher_categories.
When the lines are not commented out, I get 32 rows. The duplicated ones just have NULL for all field values.

#23

BoldMinded (Brian)

Jan 24, 2019

What category id are you working with where you see the 32 rows? Are you able to replicate this repeatedly? E.g. saving a category and suddenly there are twice as many rows as expected with a bunch of null values? I was looking at #288 and it seems to be saving fine.

#24

Hop Studios

Jan 24, 2019

It is when you create a new category, following the steps:
1. Create a new category custom field
2. Create a new category with some data entered for the custom field
3. Go to publisher categories and edit the category
4. Hit save and observer the database rows

#25

BoldMinded (Brian)

Jan 24, 2019

Ok, so I can replicate it and I see that it is not adding empty rows if I comment out those two lines, but this only happens in your environment. I can’t replicate this locally in two different environments. Have you tried to replicate this in another environment? Have you tried upgrading to EE 5, if at least temporarily or on another server, to see if the issue still occurs there?

#26

BoldMinded (Brian)

Jan 24, 2019

This is extremely difficult to figure out b/c under no circumstances can I replicate it locally, and I can’t step debug your environment, so I can’t walk slowly through what is happening to identify where it is breaking down.

#27

BoldMinded (Brian)

Jan 24, 2019

Basically FTP isn’t cutting it. I don’t like doing this b/c generally it takes an excessive amount of time, but are you able to package up the site, db and all, so I can try to run it locally to debug it? I would first prefer you try to replicate this in a new environment, or upgrade to EE5 to see if it still happens in 5 first. There is something specific happening in your site that I haven’t seen before, and no one else has reported a similar bug, which makes this all the more difficult to track down.

#28

Hop Studios

Jan 25, 2019

You are right Brian. I stop focusing on the code but rather the server setup and I found that the staging site wasn’t using the latest version of PHP.
After upgrading the PHP version to 7.2, no duplicated rows are generated.

The modifications that I made for the translation statuses are in Model/Category.php

public function getTranslationStatus()
    {
        $status = [];
        $translations = $this->getTranslations();
        $customFields = count($this->CategoryGroup->getCategoryFields());

        /** @var \EllisLab\ExpressionEngine\Model\Category\Category $defaultCategory */
        $defaultCategory = ee('Model')->get('Category')
            ->filter('cat_id', $this->getCatId())
            ->first();

        $categoryFields = ee('Model')->get('CategoryField')->all();
        $requiredFields = [];
        /** @var NativeCategoryField $field */
        foreach ($categoryFields as $field) {
            if ($this->getGroupId() == $field->getProperty('group_id')) {
                $requiredFields['field_id_'.$field->getProperty('field_id')] = $field->getProperty('field_required');
            }
        }
        /** @var CategoryTranslation $translation */
        foreach ($translations as $translation) {
            /** @var FieldFacade $customFieldTranslations */
            $customFieldTranslations = $translation->getCustomFields();
            $status[$translation->getLangId()] = 'complete';

            if ($customFields && !$customFieldTranslations) {
                $status[$translation->getLangId()] = 'incomplete';
            } elseif ($customFieldTranslations) {
                $checkEmpty = true;
                foreach ($customFieldTranslations as $name => $value) {
                    // e.g. $category->field_id_N Is the custom field property something that
                    if ($value === '' && isset($defaultCategory->$name) && $defaultCategory->$name === '' && $requiredFields[$name]) {
                        $status[$translation->getLangId()] = 'incomplete';
                    } elseif (!empty($value)) {
                        $checkEmpty = false;
                    }
                }
                if ($checkEmpty) {
                    $status[$translation->getLangId()] = 'incomplete';
                }
            }

            if ($translation->getCatName() === '' && $defaultCategory->cat_name !== '') {
                $status[$translation->getLangId()] = 'incomplete';
            }
            if ($translation->getDescription() === '' && $defaultCategory->cat_description !== '') {
                $status[$translation->getLangId()] = 'incomplete';
            }
            if ($translation->getImage() === '' && $defaultCategory->cat_image !== '') {
                $status[$translation->getLangId()] = 'incomplete';
            }
            if ($translation->getUrlTitle() === '' && $defaultCategory->cat_url_title !== '') {
                $status[$translation->getLangId()] = 'incomplete';
            }
        }

        return $status;
    }

Basically I’m checking if the custom fields are required. The status will be lit if
1. There is at least 1 field that is not empty
2. All required fields are not empty

#29

BoldMinded (Brian)

Jan 27, 2019

I think that change makes sense. I’ll probably merge it into the next release. Thanks for the suggestion.

#30

BoldMinded (Brian)

Jan 28, 2019

I found that the staging site wasn’t using the latest version of PHP. After upgrading the PHP version to 7.2, no duplicated rows are generated.

I find that odd b/c I have a 5.6 and 7.1 environment in which I can’t reproduce the error. I’m not sure how upgrading to 7.2 would fix that.

#31

Hop Studios

Feb 11, 2019

Comment has been marked private.

#32

Hop Studios

Feb 11, 2019

Is {publisher:current_language_prefix} returning empty because the segments doesn’t take the language prefix into account? If this is the intended behaviour, when do we use {publisher:current_language_prefix}?

#33

Hop Studios

Feb 11, 2019

Also, I need to modify this line in Model/CategoryTranslation.php @ line 442

$fields = $this->getCategoryFields($this->getGroupId());

without $this->getGroupId(), the site still loads and translation seems to work but I get some errors that says:
Notice
Undefined index: name
user/addons/publisher/Model/CategoryTranslation.php, line 446
Severity: E_NOTICE

#34

BoldMinded (Brian)

Feb 12, 2019

{publisher:current_language_prefix} will only have a value if the url should have a prefix in it, so if Publisher is set to not show a prefix for your default language, or not on the home page for example, than that value will be blank, otherwise it’ll show whatever prefix is in the url at the time. I forget the reason that variable was added, but it can be useful in some cases. If you need to know what the prefix is at all times, regardless if it’s in the url or not, use {publisher:current_language_code}

#35

BoldMinded (Brian)

Feb 12, 2019

Comment has been marked private.

#36

Hop Studios

Feb 12, 2019

Comment has been marked private.

#37

BoldMinded (Brian)

Feb 12, 2019

It looks like the translations for that category are blank, so I’m assuming you saved that category. I see locally that saving a category does not save the translated custom fields properly. I didn’t think any changes I made this morning would do that, so I didn’t test saving a category, only loading it. I’ll take another look…

#38

BoldMinded (Brian)

Feb 12, 2019

Comment has been marked private.

#39

Hop Studios

Feb 12, 2019

Comment has been marked private.

#40

BoldMinded (Brian)

Feb 15, 2019

1) I think I saw this happen locally a few weeks ago and forgot to take a look into it, thanks for the reminder.

2) Are you using {translated_url} or {switch_language_url} in your language switcher?

#41

Hop Studios

Feb 15, 2019

I’m using switch_language_url in the language switcher. So if switch the language to fr, if I have Link in the HTML, I expect to go to /fr/broadcast when I click that Link. But that is not the case right now, I get to /broadcast after a few seconds of the page has redirected you too many times error. Can you see if you can replicate this behaviour?

#42

BoldMinded (Brian)

Feb 15, 2019

Take a look at your URL Translation settings. Have you tried disabling “Hide the prefix for default language” to see if it fixes it? I see the redirect happening, but that could be unrelated to Publisher. People have had htaccess, server side redirects, or other funky things in place to perform redirects that have messed with Publisher’s language switching before. I’m 99.9% confident that the language switching is working as expected.

#43

BoldMinded (Brian)

Feb 15, 2019

Comment has been marked private.

#44

BoldMinded (Brian)

Feb 16, 2019

Is it possible that the changes made for the iframe stuff are causing this issue? Have you tried rolling back your code to before those iframe changes to see if the issue still occurs? Or tried setting up a new EE environment with just Publisher installed with a couple of languages, and the same Publisher settings as your current site to see if the issue still happens? I’m not trying to say it isn’t Publisher’s fault, but I feel something like this if it was a wide spread issue would have been noticed by myself and other people. So logically I’m leaning towards something specific with your environment that may be causing that behavior.

#45

Hop Studios

Feb 27, 2019

Comment has been marked private.

#46

BoldMinded (Brian)

Feb 28, 2019

Can you provide CP and FTP access to that environment?

#47

BoldMinded (Brian)

Feb 28, 2019

Actually can you create a new ticket with the description from your last comment, and put the cp and ftp info in that ticket. We’re talking about something totally new now so I want to close this ticket.

Login to reply

Contact

For add-on support, please use the Support section. General inquries and pre-sale questions can be sent to support@boldminded.com.