• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Disabling the WYSIWYG editor on just 1 forum...

#1
As the title says...

I thought this would work but it didn't...

PHP:
<xen:hook name="editor" params="{xen:array 'editorId={$editorId}'}">
  <div>
    <xen:if is="{$showWysiwyg}">
      <xen:if is="{$forum.node_id} !== 20">
        <textarea name="{$formCtrlNameHtml}" id="{$editorId}_html" class="textCtrl MessageEditor" style="display:none; {xen:if $height, 'height: {$height};'}">{$messageHtml}</textarea>
        <noscript>
        <textarea name="{$formCtrlName}" id="{$editorId}" class="textCtrl MessageEditor" style="{xen:if $height, 'height: {$height};'}">{$message}</textarea>
        </noscript>
        <xen:else />
        <textarea name="{$formCtrlName}" id="{$editorId}" class="textCtrl MessageEditor" style="{xen:if $height, 'height: {$height};'}">{$message}</textarea>
      </xen:if>
      <xen:else />
      <textarea name="{$formCtrlName}" id="{$editorId}" class="textCtrl MessageEditor" style="{xen:if $height, 'height: {$height};'}">{$message}</textarea>
    </xen:if>
    <input type="hidden" name="_xfRelativeResolver" value="{$requestPaths.fullUri}" />
    <xen:if is="{$showWysiwyg}">
      <xen:include template="editor_js_setup" />
    </xen:if>
  </div>
</xen:hook>
<xen:edithint template="editor_contents.css" />
<xen:edithint template="editor_ui.css" />
<xen:edithint template="form.css" />
Anyone mind pointing me in the right direction? thanks in advance...
 

cclaerhout

Well-known member
#2
The $forum variable is not available here
check: {xen:helper dump, $forum}

Edit: the available variables there are:
  1. 'showWysiwyg'
  2. 'height
  3. 'formCtrlNameHtml'
  4. 'formCtrlName'
  5. 'editorId'
  6. 'message'
  7. 'messageHtml'
  8. 'smilies'
  9. 'editorOptions'
Which means you can't do here what you want.
 

Chris D

XenForo developer
Staff member
#4
As far as the editor template is concerned, it has absolutely no idea what forum it is being called in. The editor template doesn't understand the parameter "{$forum}".

You can always test things by placing this in the template:

{xen:helper dump, $forum}

When I enter that, the editor template now displays "NULL" instead of any forum details.

It also doesn't understand the "$node" parameter.

This can be achieved either with a custom add-on or a code edit. A custom add-on would be much better.

But here's the code edit. Editing library/XenForo/ViewPublic/Thread/View.php:

Add the code in red

Code:
class XenForo_ViewPublic_Thread_View extends XenForo_ViewPublic_Base
{
	public function renderHtml()
	{
		$bbCodeParser = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Base', array('view' => $this)));
		$bbCodeOptions = array(
			'states' => array(
				'viewAttachments' => $this->_params['canViewAttachments']
			)
		);
		XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages($this->_params['posts'], $bbCodeParser, $bbCodeOptions);

		if (!empty($this->_params['canQuickReply']))
		{
			$editorOptions = array();
			if ($this->_params['forum']['node_id'] == 2)
			{
				$editorOptions['disable'] = true;
			}
			$this->_params['qrEditor'] = XenForo_ViewPublic_Helper_Editor::getQuickReplyEditor($this, 'message', '', $editorOptions);
		}
	}
}
 

Chris D

XenForo developer
Staff member
#6
No, sorry.

You would only need the View.php code edit above. You wouldn't need to edit the editor template at all.

See, this part is what disables the editor in forum ID 2:

Code:
		if ($this->_params['forum']['node_id'] == 2)
			{
				$editorOptions['disable'] = true;
			}
This is the Thread View so the forum parameter is there. So we can say if it is node_id 2, then disable the editor.
 

cclaerhout

Well-known member
#7
and making that change to view.php would make it understand $forum.node_id?
The problem with the editor template is that it's not included with the traditional xen tag include. So you can not map a new variable here without modifying php... but I think you will have to modify a lot of files:
  • ViewPublic/Thread/Create.php
  • ViewPublic/Thread/Reply.php
  • ViewPublic/Post/Edit.php
  • ViewPublic/Post/EditInline.php
 
#8
No, sorry.

You would only need the View.php code edit above. You wouldn't need to edit the editor template at all.

See, this part is what disables the editor in forum ID 2:

Code:
 if ($this->_params['forum']['node_id'] == 2)
{
$editorOptions['disable'] = true;
}
This is the Thread View so the forum parameter is there. So we can say if it is node_id 2, then disable the editor.
ah I see, should have looked at your code more closely, thanks!
 
#9
The problem with the editor template is that it's not included with the traditional xen tag include. So you can not map a new variable here without modifying php... but I think you will have to modify a lot of files:
  • ViewPublic/Thread/Create.php
  • ViewPublic/Thread/Reply.php
  • ViewPublic/Post/Edit.php
  • ViewPublic/Post/EditInline.php

yeah, it does seem like a lot of work... thanks for the help!
 

Chris D

XenForo developer
Staff member
#12
Yes, Cédric makes a good point.

That will only remove the quick reply editor from the thread itself. Removing it from the edit pages, create thread pages, reply thread pages actually requires more code edits in different files.

Are you sure you want to do this? :p
 

Chris D

XenForo developer
Staff member
#14
I know what you want to do.

But the WYSIWYG editor shows up in several places.

It shows up in the thread, it shows up when you create a thread, it shows up when you click on "More Options" and it shows up when you edit a post in an overlay, or click through to the main edit screen.

My code edit will only stop it from appearing in the quick reply box at the bottom of the thread.
 
#15
Ah ok... more information, yes... good...

I actually (which I should have said earlier) only want this change to take pace when creating a new thread on specific forum.

So I would have to do something like the change you did in view.php on create.php....
 

Chris D

XenForo developer
Staff member
#16
Yeah very similar.

library/XenForo/ViewPublic/Thread/Create.php

PHP:
<?php

class XenForo_ViewPublic_Thread_Create extends XenForo_ViewPublic_Base
{
	public function renderHtml()
	{
		if (!empty($this->_params['captcha']))
		{
			$this->_params['captcha'] = $this->_params['captcha']->render($this);
		}
		
		$editorOptions = array();
		if ($this->_params['forum']['node_id'] == 2)
		{
			$editorOptions['disable'] = true;
		}		

		$this->_params['editorTemplate'] = XenForo_ViewPublic_Helper_Editor::getEditorTemplate($this, 'message', '', $editorOptions);
	}
}