You are here

function cms_content_sync_form_menu_edit_form_alter in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x cms_content_sync.module \cms_content_sync_form_menu_edit_form_alter()
  2. 2.0.x cms_content_sync.module \cms_content_sync_form_menu_edit_form_alter()

Implements hook_form_menu_edit_form_alter().

Provide "push changes" action link.

File

./cms_content_sync.module, line 1933
Module file for cms_content_sync.

Code

function cms_content_sync_form_menu_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $links = [];
  if (!empty($form['links']['links'])) {
    $links = Element::children($form['links']['links']);
  }
  foreach ($links as $link_key) {
    $link = $form['links']['links'][$link_key];

    /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $menu_link */
    $menu_link = $link['#item']->link;
    if (!method_exists($menu_link, 'getEntity')) {
      continue;
    }

    // We need to get an Entity at this point,
    // but 'getEntity' is protected for some reason.
    // So we don't have other choice here but use a reflection.
    $menu_link_reflection = new ReflectionMethod('\\Drupal\\menu_link_content\\Plugin\\Menu\\MenuLinkContent', 'getEntity');
    $menu_link_reflection
      ->setAccessible(TRUE);
    $menu_link_entity = $menu_link_reflection
      ->invoke($menu_link, 'getEntity');
    $form['links']['links'][$link_key]['operations']['#links'] += cms_content_sync_get_publish_changes_operations($menu_link_entity);
  }
}