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"
0

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
    does not work. it is disabled and still i can see it in the form. – Forey Vitaliy Sep 11 '18 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']);
  }
}
  • interesting idea but did not work in my case. – Forey Vitaliy Sep 11 '18 at 14:21
  • you should clear cashe, and check if the hook is called or not ! – Adil Ech-charafi Sep 11 '18 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) – Forey Vitaliy Sep 11 '18 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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