Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2024-12-10 05:49:16

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,631
Website

Re: Plugin to change author on write tab

jakob wrote #338463:

If you replace sort_display with categories, it gets inserted at the end of the categories region (within it rather than after it). If you want to have it within an existing region (after all, having a region with twister dropdown all to itself feels a bit extreme), you could strip the wrapRegion function out of the article_author_select() function, leaving just the inputLabel bit. But where does it fit best? Perhaps in the “Meta” region somewhere?

Yes, I noticed, a little surpised, after posting that the “author” widget was now inserted inside the “Categories” group.

From my perspective –and given the limitations of plugable_ui– inserting it in the “Meta” group seems the better option. It might be less visible than a dedicated group, but up there at the top it feels it wants to much attention.

Based on your pointers (thanks), I’ll give it a try later.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#17 2024-12-12 06:39:54

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,631
Website

Re: Plugin to change author on write tab

I finally got around trying to change the position

step 1: simplify the widget, only output the label and select. This was easy (except I first left a redundant )…).
step 2, change the position, here I put meta for the “Meta” block, but nothing happened, no field was inserted in the targeted block. I then tried again with categories, that worked but inserted the field twice (I have 2 additional authors, related?)

I noticed in include/txp_article.php that the entry for categories section has this

$html_categories = pluggable_ui('article_ui', 'categories',
$partials['categories']['html'], $rs);

no such line exist for the meta section

Last edited by phiw13 (2024-12-12 06:40:22)


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#18 2024-12-12 07:41:30

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,182
Website GitHub

Re: Plugin to change author on write tab

phiw13 wrote #338501:

I then tried again with categories, that worked but inserted the field twice (I have 2 additional authors, related?)

Interesting. It does. I don’t think it’s author-related. My guess is the callback fires for each category dropdown, for example to allow you to modify each dropdown (e.g. to remove some choices from the dropdown). The pluggable_ui function can be used to modify the existing output or, as here, append something to it.

I’m not sure of a solution here. I suppose one could check in the plugin if the callback function has already been called (e.g. set a flag) and then prevent it from functioning a second time (if the flag has already been set).

EDIT: that works. Try this in conjunction with the categories callback:

protected function article_author_select($default, $rs)
{
    global $txp_user, $jcr_author_select_has_fired;

    // Check if function has already fired and if so abort
    if ($jcr_author_select_has_fired) {
        return;
    }

    $out="";
    $author = !empty($rs['AuthorID']) ? $rs['AuthorID'] : $txp_user;
    $all_authors = array();

    foreach (safe_rows("name, RealName", 'txp_users', "1=1 ORDER BY RealName ASC") as $user) {
        extract($user);
        $all_authors[$name] = $RealName;
    }

    // Only output author select if the site has multiple authors
    if (count($all_authors) > 1) {
        $out = inputLabel(
            'authorID',
            selectInput('AuthorID', $all_authors, $author, false),
            'author',
            array('', 'instructions_authorID'),
            array('class' => 'txp-form-field authorID')
        );
    }

    // Remember that function has fired
    $jcr_author_select_has_fired = true;

    return $default.$out;
}

The changes are (alongside the dropdown-only output): add this at the top of the function:

global $txp_user, $jcr_author_select_has_fired;

if ($jcr_author_select_has_fired) {
    return;
}

and this at the bottom before the return statement:

$jcr_author_select_has_fired = true;

Maybe Stef or Oleg have a more elegant way of determining if a callback function has already been called.

I noticed in include/txp_article.php that the entry for categories section has this … but no such line exist for the meta section

You’re right: try using url_title, description or keywords depending on where you want it to appear. The callbacks for pluggable_ui are listed in the docs.


TXP Builders – finely-crafted code, design and txp

Offline

#19 2024-12-12 08:10:20

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,631
Website

Re: Plugin to change author on write tab

jakob wrote #338502:

You’re right: try using url_title, description or keywords depending on where you want it to appear. The callbacks for pluggable_ui are listed in the docs.

Oh, that does it: screengrab. Great suggestion. One widget and saving works fine (at least these field: body, meta, categories so far)

I might try your other suggestions later (Placing this widget in the “Meta” block feels quite OK).

I’ll put it on my partners site, where I sometimes am an accidental author, although nobody ever sees it…)


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

Board footer

Powered by FluxBB