This issue was unnoticed up until I started working on the 'Edit' option for the widget. When $entity_element is initialized, it uses values from the editor object. After initialization it checks appends values from form attributes if they are set. Since values from editor object are given priority over those from the actual from. So, if a user chooses to edit an entity and changes entity id/uuid, form attribute will change but the editor object will still supply old value.

Turns out its a trivial fix: we just need to assign values from form attribute to entity element before those from editor object.

Concerned code is:

  public function buildForm(array $form, array &$form_state, FilterFormat $filter_format = NULL) {                                                    
    // The default values are set directly from \Drupal::request()->request,                                                                          
    // provided by the editor plugin opening the dialog.                                                                                              
    if (!isset($form_state['entity_element'])) {                                                                                                      
      $form_state['entity_element'] = isset($form_state['input']['editor_object']) ? $form_state['input']['editor_object'] : array();                 
    }                                                                                                                                                 
    $entity_element = $form_state['entity_element'];                                                                                                  
    if (!empty($form_state['values']['attributes'])) {                                                                                                
      $entity_element += $form_state['values']['attributes'];                                                                                         
    }                                                                                                                                                 

Comments

cs_shadow’s picture

Status: Active » Needs review
slashrsm’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.