Jump to content

Show data in locked custom field – 'Locked' field not showing


jonatan
 Share

Recommended Posts

collapsedNoLocked field not showing

Hi all, ☺️

I'm a 21 years old ?‍?, danish ??, hobby-designer-and-web-stuff-maker and very excited and eager processwire beginner, or "noob" ? if you wish.

So far I've been fascinated by the very satisfyingly simple and yet powerfull magic  of PW (once you get the hang of it) and the awesome feeling of the strong PW community ??☀️❤️! The huge work done by @ryan and all of the other amazing PW people is just so inspiring! I actually really have a hard time understanding why Processwire isn't the most used CMS in the world... or at least just a way more commonly known one!

 

But now I've encountered a small bump on the road and I'd lovingly appreciate if one of you lovely PW forum members could maybe help me out!

Problem:

So I have a problem with the collapsed-constant: https://processwire.com/api/ref/inputfield/#pwapi-methods-collapsed-constants 

- It's not showing my field when I apply it.

(I've funnily enough found this old git pull from 2014 which documents the "Locked" state being added as a field -> input -> visibility option: https://github.com/ryancramerdesign/ProcessWire/pull/457 – it also shows the relevant code implementations to the core) 

 

? What I wish to do:

  •  is to ? display some data from a ? module (InstagramBasicDisplayApi) in the ⌨️ page editor when editing a page ("About me") using the template (About.php)

- So the only possible way to do that as far as for what I've been able to come up with with my restricted PW (end eh.. php) –knowledge was to add a custom field type to the (About.php) template...

I've set up a custom field using https://modules.processwire.com/modules/mystique/ :

site/modules/configs/Mystique.php:

<?php


namespace ProcessWire;


                        $modules = wire("modules");
                        $instagram = $modules->get("InstagramBasicDisplayApi");
                        $data = array('username'=>'');
                        $account = $instagram->getUserAccount($data["username"]);
                        $username = isset($account["username"]) ? $account["username"] : "";
                        $at_instausername = "@" . $username;


/**
 * Resource : Instagram account
 */
return [
    'title' => __('Instagram account'),
    'fields' => [
        'window_title' => [
            'label' => __(' '),
            'type' => Mystique::TEXT, // or InputfieldText
            'useLanguages' => true,
            'collapsed' => '0',


                'placeholder' => __($at_instausername),


        ]
    ]
];

- Basically:

  1. I'm getting the instagram-username, pulling it from the module "InstagramBasicDisplayApi", 
  2. And then I'm using it as the 'placeholder' value for the field, resulting in this:

1272802216_Skrmbillede2020-03-21kl_01_05_17.png.9a6afe3007588a2bbac92124f16641a0.png - Which is actually what I want... almost...

– The thing is, I would like it to be locked, so that it's not possible to overwrite the 'placeholder' value, but so that the inputfield actually does not take any input but just informatively displays the data...

so what I do is that I just change 'collapsed' to '7' = 'collapsedNoLocked':

'collapsed' => '7',

, right, and that would be it?

But unfortunately no...

When I do I get this:

 

884102074_Skrmbillede2020-03-21kl_01_23_11.png.51991520ac266de8c37ab07fe434eef6.png - I can't figure out why? I'd supposed that the 'placeholder' value would just show, but non-editable?

A "workaround" is to just set it to back to 0, then manually type in "@sasha_lindegaard" and then press save, and then set it to 7, and I have what I want:

1660988900_Skrmbillede2020-03-21kl_01_27_44.png.b0cc3e0392086e14584000aa80d7e173.png

- But that's not really what I wish, as it displays the data (the instagram username) statically (from what I've typed into the field and have saved) and not dynamically (from the instagram module database) as wished for...

– also, it's still collapsable? Why so?... ?

 

Any ideas for how I might get my "INSTAGRAM" field to display the username from the instagram module's database dynamically, not as editable placeholder text in a editable/open input field but just as non-editable/locked text?

I hope that I've made my problem clear enough but if I've failed to provide enough info please don't hesitate to request for more! ? 

Thanks a thousand times in advance!

All the best,

Jonatan R.

Link to comment
Share on other sites

Hi @jonatan and welcome to the forums. The "Open when populated + Closed when blank + Locked (not editable)" is the closest to what you are looking for. You might actually want to add your support to this request: https://github.com/processwire/processwire-requests/issues/346

Back to your original question, I haven't used Mystique, so not sure what its limitations might be on this front, but I wonder if you can make use of https://github.com/Toutouwai/FieldtypeRuntimeOnly to add the instagram data in a runtime field.

  • Thanks 1
Link to comment
Share on other sites

@adrian Thank you so much!!!!! ?☀️??? And thank you for such an amazing response time!

 

1 hour ago, adrian said:

You might actually want to add your support to this request: https://github.com/processwire/processwire-requests/issues/346

- Done!

 

1 hour ago, adrian said:

but I wonder if you can make use of https://github.com/Toutouwai/FieldtypeRuntimeOnly to add the instagram data in a runtime field.

- Worked like a charm!!!!

Strongly back on the I-love-processwire-and-think-it-is-so-amazing-train! ???

 Solution:

Installed RuntimeMarkup Fieldtype module, made a new field with that type:

1116637995_Skrmbillede2020-03-21kl_04_17_39.thumb.png.e5718aed4884342cbd7ae874ce177d38.png

DETAILS > :

852469111_Skrmbillede2020-03-21kl_04_18_00.png.82e58ba2ae91fa724f778abe16d734e7.png

 

Edited runtime php file:

site/templates/instagramaccountid.php:

<?php

namespace ProcessWire;
                        $instagram = $modules->get("InstagramBasicDisplayApi");
                        $data = array('username'=>'');
                        $account = $instagram->getUserAccount($data["username"]);
                        $username = isset($account["username"]) ? $account["username"] : "";
                        $at_instausername = "@" . $username;
                        echo$at_instausername;
                        ?>

Result:

One piece of beautifully dynamically called data shown in as sweet plain text in the defined field in the template:

1086413082_Skrmbillede2020-03-21kl_04_23_36.png.e7264f87e9a208206d46ab3af5e4029a.png

 

Could be really cool though if this kind of custom field would maybe become integrated in the core? As well as an "locked / unlocked" option for all fields? 

 

Thanks again!

All the best,

Jonatan

  • Like 1
Link to comment
Share on other sites

@jonatan - looks like you used http://modules.processwire.com/modules/fieldtype-runtime-markup/ rather than https://github.com/Toutouwai/FieldtypeRuntimeOnly but they both do much the same thing. Anyway, glad you got it working and thanks for chiming on that Github request - that visibility stuff definitely needs an overall.

  • Like 2
Link to comment
Share on other sites

Hi @jonatan and welcome to the forum ? 

EDIT: Just saw that you are using the Mystique field. So you could have done just that (untested):

$insta = ...; // your logic

return [
    ...
    'fields' => [
        'insta' => [
            'label' => 'Instagram User',
            'type' => 'markup',
            'value' => $insta,
        ],
...

 

  • Thanks 1
Link to comment
Share on other sites

Thank you @bernhard!! ☺️

5 hours ago, bernhard said:

'type' => 'markup',

'collapsed' => '9',

'value' => $insta,

 

– Tested! – Heureka! That worked as well! :

996912863_Skrmbillede2020-03-21kl_18_10_25.png.e47ca001277a5b2d3aada8a27706e93c.png

I just simply couldn't figure out that the 'value' was all that needed haha. But it works perfectly fine!

Link to comment
Share on other sites

That's somthing you'll understand once you understand how the PW admin works. What is an Inputfield? What is a Fieldtype? What is a module, what a ProcessModule etc. ? PW has everything abstracted so that it is simple for the general user, but it is on the other hand still very powerful for advanced use. My tutorial about backend pages might be a good read ? 

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...