Jump to content

Making update proof copy of an edited core module


ocr_b
 Share

Recommended Posts

Hi,

i changed one line in the JS code of the InputfieldRepeater.js in /wire/modules/Fieldtype/FiletypeRepeater to have this field behave like i want:
instead of appending the new items to the container it should prepend them, so every new item is on top instead of at the bottom.

$inputfields.prepend($addItem);
// $inputfields.append($addItem);

how would i make this change update proof? can i just copy the file to /site/modules/(...)? or is there any smooth way to hook into this javascript function?

best,
ocr_b

Link to comment
Share on other sites

If there is no hook you can copy the file to the site directory and in the setting of the module you can select which version you want to use. I usually store them in /site/wire/ so I know which modules I've overwritten. I have to say I haven't used this much lately.

  • Like 2
Link to comment
Share on other sites

Here's a little snippet for site/ready.php that lets you store your modified copy of the js file in question under site/modules/FieldtypeRepeater/ and replaces the URL in a renderReadyHook on InputfieldRepeater:

<?php namespace ProcessWire;

wire()->addHookAfter("InputfieldRepeater::renderReadyHook", null, "useRepeaterSiteJS");

function useRepeaterSiteJS(HookEvent $event) {
	
	$config = $event->object->config;
	$modules = $event->object->modules;
	
	foreach($config->scripts as $script) {
		if(strpos($script, $config->urls->InputfieldRepeater . "InputfieldRepeater") !== false) {
			$altName = "InputfieldRepeater.js";
			$altPath = $config->paths->siteModules . "FieldtypeRepeater" . DIRECTORY_SEPARATOR . $altName;

			if(file_exists($altPath)) {
				$altUrl = $config->urls->siteModules . "FieldtypeRepeater/" . $altName;
				
				$info = $modules->getModuleInfo("InputfieldRepeater", array('verbose' => false));
				$version = $info["version"] ?: 0;
				$modified = filemtime($altPath);
				
				$config->scripts->remove($script);
				$config->scripts->add($altUrl . "?v=$version-$modified");
				
				break;
			}

		}
	}
}

Edit: amended the text to make it clear that this approach is only about the js file in question, differing from other suggestions that duplicate the complete module. Of course, incorporating changes in the original js file on every update has to be done anyway.

  • Like 1
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...