Jump to content

Select default image field (formerly 'pwAssetPageID') in TinyMCE


chrik
 Share

Recommended Posts

With InputfieldCKEditor there used to be the pwAssetPageID property that could be added to the Custom Config Options in the Input tab. It let you define a page whose image field was used by default when clicking on the Image button in the editor.

This was very handy if you wanted to embed recurring images from a central page instead of uploading them to each page where you needed them. (I think the feature stopped working at some point, however.)

Is there a way to achieve the same behavior with TinyMCE?

Link to comment
Share on other sites

You can use a hook in /site/ready.php to set the page that images will be selected from, if you want it to be different than the default. The hook will work for both CKEditor and TinyMCE.

$wire->addHookBefore('ProcessController::execute', function(HookEvent $event) {
	$input = $event->wire()->input;
	$page = $event->wire()->page;
	$pages = $event->wire()->pages;

	// Return early if the process is not ProcessPageEditImageSelect
	if(!$page || $page->process != 'ProcessPageEditImageSelect') return;

	// The ID of the page that is open in Page Edit
	$edit_page_id = (int) $input->get('edit_page_id');
	// The ID of the page that images will be selected from by default
	// Often this is the same as $edit_page_id, but it can be different in the case of Repeater items, etc.
	$images_page_id = (int) $input->get('id');

	// Check that the $edit_page_id is populated, otherwise the user will not
	// be able to manually choose a different page to select images from
	if(!$edit_page_id) return;

	// Optionally do some test using $edit_page_id and/or $images_page_id
	$edit_page = $pages->get($edit_page_id);
	if($edit_page->template != 'basic_page') return;

	// Set a different ID for the page that images will be selected from
	// e.g. select images from the home page
	$input->get->id = 1;
});

 

Edited by Robin S
Added additional check to allow user to manually choose a different page to select images from
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • chrik changed the title to Select default image field (formerly 'pwAssetPageID') in TinyMCE

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...