0

I'd like to tell my user who is adding an entry via the CP to do something. This doesn't have to do with any field, it's simply an instruction on what to do next.

Specifically, I hide the "Photo" field because these users can't be trusted to upload a professional photo; instead they are supposed to contact an admin to add their photo.

This instruction can be inside the Edit Entry interface somewhere, or even on the next page, after Submit has been clicked.

Any recommended way to do this?

3 Answers 3

1

Did you try Publish Notes fieldtype? It allows you to add instructions to CP.

Publish Notes

1

Probably the easiest way is to create an extension that is fired by these hooks:

https://docs.expressionengine.com/latest/development/extension-hooks/cp/css.html https://docs.expressionengine.com/latest/development/extension-hooks/cp/javascript.html

Then you can just inject JavaScript and CSS in to your Control Panel.

Here's an example of the two methods you could fire in your extension:

function add_cp_tweaks_css()
{
    $css .= file_get_contents(PATH_THIRD."my_cp_extension/css/cp.css");
    return ee()->extensions->last_call . "\n" . $css;
}

function add_cp_tweaks_js()
{
    $js .= file_get_contents(PATH_THIRD."my_cp_extension/js/cp.js");;
    return ee()->extensions->last_call . "\n" . $js;
}

Then in your CSS file and JavaScript file, just manipulate the DOM as necessary.

// cp.css
.my-message {
    font-weight: bold;
}

// cp.js
$(".t-0").prepend('<div class="my-message">You are not allowed to add pictures. Contact an admin.</div>');

Based on your use case, you'll need to probably want to add checks to make sure you only insert your JavaScript and CSS on Entry pages, and also want to check what user group the member is so you don't add the message to SuperAdmins or those who are allowed. So something like this:

$user_group_to_show_message = 10;

$referer = (array_key_exists('HTTP_REFERER',$_SERVER) ? $_SERVER['HTTP_REFERER'] : '');

// Check if we're on a publish page
preg_match('/.*publish\/(create|edit\/entry)\/([0-9]+).*/', $referer, $match);

if (array_key_exists(2,$match)
    && is_numeric($match[2])
    && ee()->session->userdata('group_id') === $user_group_to_show_message) {
    // We are on a Publish page, with the right user group to warn, go ahead and add CSS/JS
}
-1

I believe the best approach would be to make a custom fieldtype, you could then include this in any channel form at will without any further programming. The fieldtype could just be a label/text with no input. https://docs.expressionengine.com/latest/development/fieldtypes.html

2
  • I need it in CP. Not in front end...
    – Benoit L
    Commented Jul 22, 2019 at 2:54
  • yes, I understood that, and this would work, a fieldtype with no input would have no place on the front end
    – meatpaste
    Commented Jul 22, 2019 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.