Hello,

I believe allowing in the settings to define the URL of the forward page would allow greatly flexibility and usage for a wider audience of this awesome module.

This would allow for different combinations:
www.example.com/forward?path=node/nid
www.example.com/share?path=node/nid
www.example.com/tellafriend?path=node/nid
etc

I hope someone would be able to help add this feature to this module!

Thank you

Comments

YK85’s picture

can anyone please help?

seanr’s picture

This is a bit more difficult than it would seem, since you'd be dynamically generating the menu items. Then you run into the fact that the menu items are cached, so that'd need to be cleared each time the path was changed. I'll look into doing it, but it'll take me some time as I've got a lot on my plate at the moment.

john.oltman’s picture

Version: 6.x-1.x-dev » 8.x-1.x-dev
Issue summary: View changes
dww’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev

Yeah, this would be nice.

I solved this for my site with a custom controller and menu item that looks up the node from a URL alias and spits out the appropriate forward form. Something like this:

sw.routing.yml:

sw.email:
  path: '/email/{year}/{month}/{day}/{title_alias}'
  defaults:
    _controller: '\Drupal\sw\Controller\SWController::emailStoryPage'
    _title: 'E-mail'
  requirements:
    _permission: 'access content'

src/Controller/SWController.php:


namespace Drupal\sw\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\forward\ForwardFormBuilder;
use Drupal\sw\EntityPathAliasTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Provides route responses for the SW module.
 */
class SWController extends ControllerBase {

  use EntityPathAliasTrait;

  /**
   * The forward form builder service.
   *
   * @var \Drupal\forward\Form\ForwardFormBuilder
   */
  protected $forwardFormBuilder;

  /**
   * Constructs a ForwardController object.
   *
   * @param \Drupal\forward\Form\ForwardFormBuilder $form_builder
   *   The forward form builder service.
   */
  public function __construct(ForwardFormBuilder $forward_form_builder) {
    $this->forwardFormBuilder = $forward_form_builder;
  }
...
 /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('forward.form_builder')
    );
  }

  /**
   * Returns the forward form for a given story.
   *
   * @return array
   *   Render array for email-this-story form.
   */
  public function emailStoryPage($year, $month, $day, $title_alias) {
    $path_alias = "/$year/$month/$day/$title_alias";
    $node = $this->loadNodeFromAlias($path_alias);
    if (empty($node)) {
      // If we're on a broken link and can't load a story at that alias, bail.
      throw new NotFoundHttpException();
    }
    // Force the "link" interface so the Forward form page doesn't build inside a fieldset.
    $settings = $this->config('forward.settings')->get();
    $settings['forward_interface_type'] = 'link';
    return $this->forwardFormBuilder->buildForwardEntityForm($node, $settings);
  }
...
}

That said, it'd be nice to potentially provide this as a setting directly in forward.module. Shouldn't be that hard, but given the above, I'm not desperate to spend time on this anytime soon. ;)

Cheers,
-Derek

john.oltman’s picture

Version: 8.x-3.x-dev » 8.x-2.x-dev
john.oltman’s picture

Version: 8.x-2.x-dev » 4.0.x-dev