EntityDescriptionFormTrait.php in Lightning Core 8        
                          
                  
                        
  
  
  
  
File
  src/EntityDescriptionFormTrait.php
  
    View source  
  <?php
namespace Drupal\lightning_core;
use Drupal\Core\Form\FormStateInterface;
trait EntityDescriptionFormTrait {
  
  public function form(array $form, FormStateInterface $form_state) {
    
    $entity = $this
      ->getEntity();
    $form = parent::form($form, $form_state);
    $form['description'] = [
      '#type' => 'textarea',
      '#title' => t('Description'),
      '#description' => $this
        ->t('Additional relevant information about this @entity_type, such as where it is used and what it is for.', [
        '@entity_type' => $entity
          ->getEntityType()
          ->getSingularLabel(),
      ]),
      '#rows' => 2,
      '#default_value' => $entity
        ->getDescription(),
    ];
    return $form;
  }
  
  public function save(array $form, FormStateInterface $form_state) {
    $this
      ->getEntity()
      ->setDescription($form_state
      ->getValue('description'));
    parent::save($form, $form_state);
    
    $this
      ->cacheTagInvalidator()
      ->invalidateTags([
      'block_view:help_block',
    ]);
  }
  
  private function cacheTagInvalidator() {
    return @$this->cacheTagInvalidator ?: \Drupal::service('cache_tags.invalidator');
  }
}