0

How to remove "last saved" and "author" fields in from in Drupal 8? that what i have in the end of form

answer over here did not help How do I remove the authoring information?

i have tried to hide it via form_alter but no luck...

i would appreciate any help or advice... lost to much time on this already...

part of what i get in kint($form); if this can help:

→'meta' => array(10)

'#type' => string(7) "details"

'#group' => string(8) "advanced"

'#weight' => integer-10

→'#title' => Drupal\Core\StringTranslation\TranslatableMarkup(5)

        contents Available methods (14) 

        protected translatedMarkup -> NULL

        protected options -> array(0)

        →protected stringTranslation -> Drupal\Core\StringTranslation\TranslationManager(4)
                contents Available methods (10) 

                →protected translators -> array(2)

                    →'30' => array(1)

                        *DEPTH TOO GREAT*

                    →'0' => array(1)

                        *DEPTH TOO GREAT*

                →protected sortedTranslators -> array(2)

                    →Drupal\Core\StringTranslation\Translator\CustomStrings(4)

                        *DEPTH TOO GREAT*

                    →Drupal\locale\LocaleTranslation(9)

                        *DEPTH TOO GREAT*

                protected defaultLangcode -> string(2) "en"

                public _serviceId -> string(18) "string_translation"

        protected string -> string(6) "Status"

        protected arguments -> array(0) 

→'#attributes' => array(1)

    →'class' => array(1)

        string(19) "entity-meta__header"

'#tree' => boolTRUE

'#access' => boolTRUE

→'published' => array(4)

    '#type' => string(4) "item"

    →'#markup' => Drupal\Core\StringTranslation\TranslatableMarkup(5)

            contents Available methods (14) 

            protected translatedMarkup -> NULL

            protected options -> array(0)

            →protected stringTranslation -> Drupal\Core\StringTranslation\TranslationManager(4)
                    contents Available methods (10) 

                    →protected translators -> array(2)

                        *DEPTH TOO GREAT*

                    →protected sortedTranslators -> array(2)

                        *DEPTH TOO GREAT*

                    protected defaultLangcode -> string(2) "en"

                    public _serviceId -> string(18) "string_translation"

            protected string -> string(9) "Published"

            protected arguments -> array(0) 

    '#access' => boolFALSE

    →'#wrapper_attributes' => array(1)

        →'class' => array(1)

            string(18) "entity-meta__title"

→'changed' => array(4)

    '#type' => string(4) "item"

    →'#title' => Drupal\Core\StringTranslation\TranslatableMarkup(5)

            contents Available methods (14) 

            protected translatedMarkup -> NULL

            protected options -> array(0)

            →protected stringTranslation -> Drupal\Core\StringTranslation\TranslationManager(4)
                    contents Available methods (10) 

                    →protected translators -> array(2)

                        *DEPTH TOO GREAT*

                    →protected sortedTranslators -> array(2)

                        *DEPTH TOO GREAT*

                    protected defaultLangcode -> string(2) "en"

                    public _serviceId -> string(18) "string_translation"

            protected string -> string(10) "Last saved"

            protected arguments -> array(0) 

    →'#markup' => Drupal\Core\StringTranslation\TranslatableMarkup(5)

            contents Available methods (14) 

            protected translatedMarkup -> NULL

            protected options -> array(0)

            →protected stringTranslation -> Drupal\Core\StringTranslation\TranslationManager(4)
                    contents Available methods (10) 

                    →protected translators -> array(2)

                        *DEPTH TOO GREAT*

                    →protected sortedTranslators -> array(2)

                        *DEPTH TOO GREAT*

                    protected defaultLangcode -> string(2) "en"

                    public _serviceId -> string(18) "string_translation"

            protected string -> string(13) "Not saved yet"

            protected arguments -> array(0) 

    →'#wrapper_attributes' => array(1)

        →'class' => array(1)

            string(23) "entity-meta__last-saved"

→'author' => array(4)

    '#type' => string(4) "item"

    →'#title' => Drupal\Core\StringTranslation\TranslatableMarkup(5)

            contents Available methods (14) 

            protected translatedMarkup -> NULL

            protected options -> array(0)

            →protected stringTranslation -> Drupal\Core\StringTranslation\TranslationManager(4)
                    contents Available methods (10) 

                    →protected translators -> array(2)

                        *DEPTH TOO GREAT*

                    →protected sortedTranslators -> array(2)

                        *DEPTH TOO GREAT*

                    protected defaultLangcode -> string(2) "en"

                    public _serviceId -> string(18) "string_translation"

            protected string -> string(6) "Author"

            protected arguments -> array(0) 

    '#markup' => string(5) "@dmin"

    →'#wrapper_attributes' => array(1)

        →'class' => array(1)

            string(19) "entity-meta__author"

4 Answers 4

1

If I understand your requirement correctly, then you should go to your content type Manage form display configuration page, it should be under: /admin/structure/types/manage/YOUR_CONTENT_TYPE/form-display
Then you should disable Authored by and/or Authored on by dragging them to the disabled area in the table, then click save
enter image description here

1
  • 2
    does not work. it is disabled and still i can see it in the form. Commented Sep 11, 2018 at 14:20
0

The information about "last saved" and "author" is under meta in form variable.
To remove it, you need to alter form and unset these variables.

function MY_MODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
  if($form_id == 'node_CONTENT_TYPE_form'){
    unset($form['meta']['changed']);
    unset($form['meta']['author']);
  }
}
3
  • interesting idea but did not work in my case. Commented Sep 11, 2018 at 14:21
  • you should clear cashe, and check if the hook is called or not ! Commented Sep 11, 2018 at 14:48
  • i flush all cashes every time i make some changes to my code and hook is called because i have this: $form['title']['#prefix'] = '<div class="my-class">'; next to what you have suggested and i get it in the form. (i have started looking to change template twig file for add/edit node, studding this option now) Commented Sep 11, 2018 at 14:54
0

The following worked for me:

    function MY_MODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
  if($form_id == 'node_CONTENT_TYPE_form'){
    $form['meta']['#access'] = FALSE;
  }
}
0

I had the same problem with claro and a group content node edit form. These did NOT work https://www.drupal.org/project/simplify/issues/3207027 https://drupal.stackexchange.com/a/134540/14822 (partially worked - empty right sidebar still displayed)

what worked for me was i. create a custom module and implement form alter like this

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter() for node form.
 */
function mymodule_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $current_user = \Drupal::currentUser();
  $roles = $current_user->getRoles();  
  if ( in_array('administrator', $roles)) {
    return;
  }
  $node = $form_state->getFormObject()->getEntity();
  if ( !in_array($node->bundle(), ['mycontenttype','myothercontenttype'])) {
    return;
  }

  $form['#attached']['library'][] = 'mymodule/mymodule_simplify_node_edit';
}

Then create a mymodule.libraries.yml file and declared this library

mymodule_simplify_node_edit:
  css:
    theme:
      css/simplify.css: {}

This allowed me to inject css for this form. Since security is not an issue and I only wanted to simplify the form for basic user this is ok.

these are the css rules i used to fix the problem

.layout-region--node-secondary {
    display: none !important;
}
.layout-region--node-main .layout-region__content, .layout-region--node-footer .layout-region__content {
    max-width: 80rem !important;
}
.layout-region--node-main {
    float: none !important;
    width:  100% !important;
}
1

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.