Boatloads of clean-up to be done:
- VERSION is used as the version in libraries, but that's wrong, because edit.module is not part of core
- the includes/editor.PROPERTYEDITORNAME.inc files don't have docblocks and particularly the CKEditor one contains a lot of weird things that are not documented
- the code in pages.inc is mostly terrible to read, and where it does have docs, they're often outdated (i.e. wrong)
- fape.inc has been left in its temporary state, but now permanently; it needs to be cleaned up now that we explicitly don't want to depend on the fape module, and the filename and function names no longer make any sense
- …

Comments

wim leers’s picture

Assigned: Unassigned » wim leers

While debugging #1946950: Node's menu link removed when changing either title, date or author via in-place editing (also: fape.inc is unmaintainable), I became even more baffled by the absolute piece of spaghetti that fape.inc is. It's impossible to understand.

Frankly, every commit made by nod_ during his D7 backport sprint has made it less understandable (that's what extreme time pressure will do). There's now two codepaths, and it's not clear why that's necessary and what the differences are.

So, to make Edit module stable and to solve #1946950: Node's menu link removed when changing either title, date or author via in-place editing (also: fape.inc is unmaintainable), I'll have to try to make sense out of fape.inc and simplify it. Potentially even add tests. Only then it will become solvable.

wim leers’s picture

There's too much to be done in this issue, so it makes sense to split this off to subissues. fape.inc clean-up and the problem with the node menu link being removed when changing title/date/author have been solved in one patch (because their problem spaces overlapped so much) over at #1946950-3: Node's menu link removed when changing either title, date or author via in-place editing (also: fape.inc is unmaintainable).

wim leers’s picture

Priority: Normal » Minor

Only remaining thing: backport D8-style in-place editor definitions to D7.

wim leers’s picture

That was wrong for a while now.

wim leers’s picture

Issue tags: -sprint

This.

wim leers’s picture

Do we really want to backport D8-style in-place editor definitions to D7? That means classes implementing an interface rather than info hooks listing callbacks and an include file. Isn't what we have now more D7-like, and shouldn't we therefor keep it?

webchick’s picture

Can I get a code snippet or something to evaluate in the context of #7?

wim leers’s picture

/**
 * Implements hook_edit_editor_info().
 *
 * @see Drupal 8's \Drupal\edit\Plugin\InPlaceEditorManager.
 * @see Drupal 8's \Drupal\edit\EditPluginInterface.
 */
function edit_edit_editor_info() {
  $editors = array();
  $path = drupal_get_path('module', 'edit');
  $editors['form'] = array(
    'compatibility check callback' => '_edit_editor_form_is_compatible',
    'metadata callback' => '_edit_editor_form_metadata',
    'attachments callback' => '_edit_editor_form_attachments',
    'file' => 'includes/editor.form.inc',
    'file path' => $path,
  );
  return $editors;
}

and

<?php

/**
 * @file
 * Defines the "plain text" in-place editor.
 *
 * @see Drupal 8's \Drupal\edit\Plugin\InPlaceEditor\PlainTextEditor.
 */

function _edit_editor_plain_text_is_compatible(array $instance, array $items) {
  $field = field_info_field($instance['field_name']);

  // This editor is incompatible with multivalued fields.
  $cardinality_allows = $field['cardinality'] == 1;
  // This editor is incompatible with processed ("rich") text fields.
  $no_text_processing = empty($instance['settings']['text_processing']);

  return $cardinality_allows && $no_text_processing;
}

function _edit_editor_plain_text_metadata(array $instance, array $items) {
  return array();
}

function _edit_editor_plain_text_attachments() {
  return array(
    'library' => array(
      array('edit', 'edit.inPlaceEditor.plainText'),
    ),
  );
}

versus

<?php

/**
 * @file
 * Contains \Drupal\edit\Plugin\InPlaceEditor\PlainTextEditor.
 */

namespace Drupal\edit\Plugin\InPlaceEditor;

use Drupal\edit\EditorBase;
use Drupal\edit\Annotation\InPlaceEditor;
use Drupal\Core\Field\FieldDefinitionInterface;

/**
 * Defines the plain text in-place editor.
 *
 * @InPlaceEditor(
 *   id = "plain_text"
 * )
 */
class PlainTextEditor extends EditorBase {

  /**
   * {@inheritdoc}
   *
   * @todo The processed text logic is too coupled to text fields. Figure out
   *   how to generalize to other textual field types.
   */
  function isCompatible(FieldDefinitionInterface $field_definition, array $items) {
    // This editor is incompatible with multivalued fields.
    if ($field_definition->getFieldCardinality() != 1) {
      return FALSE;
    }
    // This editor is incompatible with processed ("rich") text fields.
    elseif ($field_definition->getFieldSetting('text_processing')) {
      return FALSE;
    }
    else {
      return TRUE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getAttachments() {
    return array(
      'library' => array(
        array('edit', 'edit.inPlaceEditor.plainText'),
      ),
    );
  }

}
gábor hojtsy’s picture

I think what makes sense to diverge the D7/D8 codebase less. While callbacks with an info hook is more D7 like, the code looks like may diverge significantly, adding to the maintenance burden(?)

wim leers’s picture

#10: that's definitely true. OTOH, the code in these classes would in any case be pretty significantly different, because of the huge changes to Entity/Field API in D8. But it'd still be easier to map changes in D8 to changes in D7, so it might still be worthwhile.

wim leers’s picture

wim leers’s picture

Title: Clean up Edit's PHP to make it more maintainable » Clean up Edit's PHP to make it more maintainable: Drupal 8-style in-place editor definitions
Status: Postponed » Fixed

Done.

I even found a piece of dead code in the process.

http://drupalcode.org/project/edit.git/commit/58044ac

Status: Fixed » Closed (fixed)

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