Jump to content
Macrura

Soundmanager2 Audio for Processwire

Recommended Posts

Soundmanager2 Audio for Processwire

Github:

https://github.com/outflux3/TextformatterSoundmanager

Modules Directory:

http://modules.processwire.com/modules/textformatter-soundmanager/

This module provides most of the free audio player interfaces for Soundmanager2 by Scott Schiller:

  • Bar UI
  • 360 UI
  • 360+ spectrum UI
  • mp3 buttons
  • mp3 links
  • Page Player, muxtape-style UI
  • Cassette Player

The module is a Textformatter that works by allowing you to insert shortcodes which are parsed into audio players.

The players may be placed anywhere in the content (ck editor or other text field) using the shortcode, for example:

[smplayer tag=audio1]

The output will be a default single player (as specificed in the module settings), or if multiple audio files have the same tag, and you don't specify a type (UI), it will default to the Bar UI for the playlist. You may also specify page-player for the type as it also supports playlists.

Here is a more complex tag:

[smplayer tag=audio1 type=bar-ui color=2288CC]

the tags available on shortcodes are:

  • tag - *required to find the audio file on the page
  • type (the type of player)
  • limit (limit the number of files to load when using a playlist)

Player specific tags for Bar UI:

  • bar-ui (options for the bar-ui player)
  • skin (applies to a bar-ui skin to load)
  • extra (when set to true, it will display the extra controls)
  • color (hex value for color - applies to bar-ui and mp3 buttons)
  • compact (makes the player very narrow)
  • playlist-open (make the playlist drawer open instead of needing to click the playlist button to open it.)
  • dark-text (instead of white)
  • flat (remove the faux 3d effect)

When using the shortcode, you can chain the tags using underscore, for exmaple:

[smplayer type=bar-ui bar-ui=flat_playlist-open_dark_text]

Player specific tags for Cassette:

  • cassette (options for the cassette player)

In case you are not familiar with SM2, it powers a lot of major audio on the web, like Soundcloud, LastFM, AllMusic etc). The players are all rock solid and work on a wide range of browsers and devices.

Features

Multiple Audio Formats

SM2 supports many formats, and those can be enabled/disabled in the module config if you want to prevent any from being loaded. So far this module was tested with MP3 and AAC (.m4a).

GetID3 Support

When enabled, ID3 tags from every audio file that pass through the Textformatter are read and cached as arrays using WireCache. Therefore the first load of a page with new audio files may be slow while the tags are read and stored. The tags are indexed by the filename of the audio, so as long as you don't upload multiple files with the same filename, or change the tags, the system will store the metadata permanently. To remove any metadata, you would need to use Soma's Cache Admin module, or clear it from the database.

Schema Support

When enabled, some schema tags relating to audio files will be added to the markup.

CK editor Plugin

Very basic dropdown that inserts some pre-configured player codes into the editor. Copy the plugin into your CK editor plugins folder, enable and add a button for 'soundmanager'.

Edit_Page__Soundmanager2_Audio_Testing_Page_•_localhost.jpg

Instructions

Before you install:

1) You will need a files field that accepts audio files, so set the extensions you want to use, such as mp3, m4a, mp4, wav etc. 2) Also make sure that you enable tags on the files field because the module references the tags for any audio file in the shortcode. 3) Add the files field to your template.

Installation and Setup

1) Install the module and adjust your settings from the module configuration screen.

2) Add the TextformatterSoundmanager textformatter to the field where you want to insert audio (e.g. 'body').

3) Optionally install the CK editor plugin to enable quick access to preconfigured shortcodes.

4) Add a shortcode into the textarea field that has the textformatter applied to.

5) You must reference the tag you entered in the audio file's tag field in the shortcode, and that will create a player for that audio file.

5a) To create a playlist, put the same tag in multiple audio files.

Output

1) In order for the module to output the necessary styles and scripts, you need to echo the $config->styles and $config->scripts arrays into your site's header/footer. Here is an example:

// In Header
foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n";

// In Footer
foreach($config->scripts as $script) echo "<script type='text/javascript' src='{$script}'></script>\n";

 

API Usage

To access the module's player method directly, you would first init the module in your _init.php file:


    $sm2 = $modules->get('TextformatterSoundmanager');

then anywhere in your templates, you can output any audio file with any player, in an configuration like this:

    $options = [
        'type' => 'bar-ui',
        'skin' => 'gradient-fat',
        //'tag' => 'audio1', // tag is not needed when using the API
        //'bar-ui' => 'playlist-open' //all of the classes to apply to the bar ui.
    ];

    foreach($page->audio as $track) {
        $content .= $sm2->player($track, $options);
    }

Advanced Features

  • Using other pages for storing music as playlists. You can create a field to hold a tag for a **page* and then refer to that tag in your shortcode. The shortcode word would be smplaylist instead of smplayer. The module will search the site for pages with that tag in that field. Then it will output all of the audio files in that page's audio field using the player and settings you specify. See the module configuration to select the tag field and adjust your shortcode words.

Caveats

Some player will not work well on the same page as other players.

  • Bar UI and Page Player
  • 360 Player and 360 Visual (large) players

Also note that the cassette player can only occur once on a page. You can have multiple cassettes output, but they will all play the same audio file. The file that the cassette player uses is set in the script tag. In the future the setup may be modified to allow for cassette players to have their own audio files.

About Soundmanager2

http://www.schillmania.com/projects/soundmanager2/

Speak and be heard

More sound, in more places

Despite being one of the senses, sound has largely been missing from the web due to inconsistent technology support. SoundManager 2 bridges this gap, making it easier to use audio across a growing variety of devices and platforms, both desktop and mobile.

HTML5 + flash hybrid

Complexity, reduced

Supporting HTML5 audio can be tedious in modern browsers, let alone legacy ones. With real-world visitors using browsers ranging from mobile Safari to IE 6 across a wide range of devices, there can be many support cases to consider.

SoundManager 2 gives you a single, powerful API that supports both new and old, using HTML5 audio where supported and optional Flash-based fallback where needed. Ideally when using SoundManager 2, audio "just works."

The ginsu knife: 12 KB

Big features, small footprint

Performance is an important metric, too. SoundManager 2 packs a comprehensive, feature-rich API into as little as 12 KB over the wire when optimized; that's less than 8% of the original, uncompressed file size.

SM2 is self-contained, having no external dependencies, and is compatible with popular JavaScript frameworks.

The source code is BSD-licensed and is provided in fully-commented, non-debug and compiler-optimized "minified" versions appropriate for development and production use.

 

  • Like 20

Share this post


Link to post
Share on other sites

This module is now available on GitHub.

Still beta, but working well on all sites tested on. More documentation coming soon.

If anyone out there needs inline audio on your site, check this out.

** make sure to read the instructions on Github, as those will always be updated to the latest (hard to keep the instructions here sync'd with the module instructions)...

  • Like 4

Share this post


Link to post
Share on other sites

Here are some of the custom skins provided for the Bar-UI, and the shortcodes used:

 

Soundmanager2_Bar_UI.jpg

  • Like 4

Share this post


Link to post
Share on other sites

Here are some of the pre-configured cassette ui players:

Soudmanager2_Cassette.jpg

  • Like 2

Share this post


Link to post
Share on other sites

Thank you for the module. I'am trying to get it to work. Could you please check these settings?

In Header:

<?php foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n"; ?>

Before closing body tag:

<?php foreach($config->scripts as $script) echo "<script type='text/javascript' src='{$script}'></script>\n"; ?>

I created a _init.php located in 'templates'

<?php
include_once("./_func.php"); // include our shared functions

$sm2 = $modules->get('TextformatterSoundmanager');

In my config.php I added

$config->prependTemplateFile = '_init.php';

Files field added to template mp3

1923846095_Schermafbeelding2018-06-29om14_06_48.thumb.png.4e471c6ecaaf1c7dd8058a2d2f2b7cb5.png1923846095_Schermafbeelding2018-06-29om14_06_48.thumb.png.4e471c6ecaaf1c7dd8058a2d2f2b7cb5.png

 

In my template file I added:

<?php $options = [
							        'type' => 'bar-ui',
							        'skin' => 'gradient-fat',
							        //'tag' => 'audio1', // tag is not needed when using the API
							        //'bar-ui' => 'playlist-open' //all of the classes to apply to the bar ui.
							    ];
							
							    foreach($page->audio as $track) {
							        $content .= $sm2->player($track, $options);
							    } ?>

 

Share this post


Link to post
Share on other sites

It all looks correct; you can also just do this:

echo $sm2->player($page->audio, $options);

If you are not getting players showing you'd need to ensure that the settings are all correct in the module config, and then check to make sure the CSS and JS are being output on your page;

then make sure the markup is being output correctly; it would be easier once these things are checked; if you are getting styles & scripts output, and are getting markup output, and still not seeing players, check the console to see if there are any JS errors.

Share this post


Link to post
Share on other sites

How do I get the cassette interface on a page?

The text field has "[smplayer tag=cryplant type=cassette]", cassette options in the module are set to 'cutout' and 'green_color'.

Result is: https://www.performan.org/carl-cryplant/carl-cryplants-christmas-music-vol-1/ filename, a play, rewind, forward and stop button.

Also added all the scripts in header & footer, _init, etc. Probably missed out something somewhere....

Share this post


Link to post
Share on other sites

swfUrl needs to be defined, since that particular player requires flash; but the strange thing is this used to work on my local but is not currently working; i will check and see if there is some way of getting it to work again...

also on your page jquery isn't loading, because of Blocked loading mixed active content

 

Share this post


Link to post
Share on other sites

once you eliminate the errors, if you want to use that player on a page, for now you'll need to manually insert this code in the header, until i can update the module to insert that; I probably had a cached copy of the swf player on my old dev machine which is why it worked without that.. once the module is updated, then it will insert that code into the header when you have a cassette on the page..

		<script type='text/javascript'>
			var swfUrl = '/site/modules/TextformatterSoundmanager/soundmanager2/swf/';
		</script>

 

Share this post


Link to post
Share on other sites

if the tape doesn't look right you might also have to use this css:

.tape * {
  box-sizing: content-box;
}

the next version will have that in the tape css file..

Share this post


Link to post
Share on other sites

Thanks. Guess I solved a few issues but the cassette still doesn't look like a cassette because apparently it's missing something: 

[Error] Failed to load resource: the server responded with a status of 404 (Page Not Found) (ma-r90-mask.png, line 0)
https://www.performan.org/carl-cryplant/christmas-music-vol-1/image/ma-r90-mask.png

 

Share this post


Link to post
Share on other sites

so are you doing this?

) In order for the module to output the necessary styles and scripts, you need to echo the $config->styles and $config->scripts arrays into your site's header/footer. Here is an example:

// In Header
foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n";

// In Footer
foreach($config->scripts as $script) echo "<script type='text/javascript' src='{$script}'></script>\n";

I don't see the cassette css file anywhere on the page; the styles for any given player need to be either hardcoded style link references on the page, or you have to use $config scripts & styles in order for each/any of the players CSS and JS files to load;

Share this post


Link to post
Share on other sites

In Header I have my normal stylesheet ref: <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/cryplant_sets_style.css" />

And added yours as: <?php foreach($config->styles as $style) echo "<link rel='stylesheet' type='text/css' href='{$style}' />\n"; ?>. The CSS and scripts are still in the module folder.

.tape * {
  box-sizing: content-box;
}

went in the first one. 

Everything's there in Footer as well.

I presume I'm messing things up...

Share this post


Link to post
Share on other sites

i don't see the CSS file - cassette-tape-ui.css in your header; if you have Tracy, can you try debugging what is inside $config->styles? on my local machine it all works;

alternately you can hardcode the reference to the css file on that page, like this:

<link rel="stylesheet" href="/site/modules/TextformatterSoundmanager/soundmanager2/cassette-tape/css/cassette-tape-ui.css">

Share this post


Link to post
Share on other sites

Ha! Looks a lot better now. The play/pause button doesn't work, pausing works when you click on the cassette however. Maybe the jscript isn't doing wat it should, like in the example on http://www.schillmania.com/projects/soundmanager2/demo/cassette-tape/.

And for some reason the code "echo $sound->player($page->sound);" doesn't work in the template, gives "Error: Call to a member function player() on null (line 126 of /home/performaaj/www/site/templates/cryplant_sets.php)" . I have it in a text field now: [smplayer tag=cryplant type=cassette]. _init file has "$sound = $modules->get('TextformatterSoundmanager');" and my sound field is called "sound".

Share this post


Link to post
Share on other sites

you have some rules messing up the player; make sure the player CSS is loaded after your site css; The controls shouldn't appear until you hover over the cassette.

Problem 1)

#content p, #content ul, #content ol, #content table {
    margin: 1em 0 1.5em 0;
}

Problem 2)

#content ul li {
    margin: 0 0 0 3em;
    display: list-item;
    list-style: none;
}

problem 3)

#content a {
    color: #f00076;
}

once those are solved you should have it looking like this:

2083216618_ScreenShot2018-12-26at11_58_19AM.jpg.d4d98691a1a405e2a0e2135b0986555a.jpg

for the other issue, you should check to make sure that the variable $sound is not getting overwritten somewhere; for safety you should probably call it $sm2 instead of sound;

Share this post


Link to post
Share on other sites

Ok, solved the problems you mentioned and it looks as promised. The play button only acts as play and not as pause like I thought it should, during playback it acts as rewind. Clicking the cassette makes the sound pause and resume.

echo "$sm2->player($page->sound)"; in the template gives just the filename of the soundfile...

Also somewhat amazing is that the rewind and forward buttons actually jump to the next or previous song although the soundfile is a 44min mix of different tracks made with Traktor in 2006-2007. I suppose SoundManager analyses the file and finds differences in the spectrum or whatever.

Share this post


Link to post
Share on other sites
1 hour ago, BFD Calendar said:

echo "$sm2->player($page->sound)"; in the template gives just the filename of the soundfile...

not sure, it sounds like $sm2 is not the module instance; you'd need to use Tracy Debugger to bd($sm2) at that point and see if it is actually the module;
I will test your code also to see if i can troubleshoot that issue; are you passing any options to the player, or are you setting the default player as the cassette, in the module config?

Share this post


Link to post
Share on other sites
19 hours ago, BFD Calendar said:

echo "$sm2->player($page->sound)"; in the template gives just the filename of the soundfile...

the api access to the cassette ui is working for me; you just need to make sure you supply the options, because there is no way to default to the cassette for the player, because it only supports 1 audio file per page..

Soudmanager2_Cassette___Soundmanager2_Mixed_Types_Testing___My_Great_Site.thumb.jpg.4914641fae6f7fae4a4e5beda59acef6.jpg

Share this post


Link to post
Share on other sites

I did just that, renamed my field to 'audio', just in case 'sound' would conflict with anything.

Code in the template:

	$options = [
		'type' => 'cassette',
		'cassette' => 'ma-r90',
	];
	$track = $page->audio->first();
	$content .= $sm2->player($track, $options);

Result: Error: Call to a member function player() on null (line 128 of /home/performaaj/www/site/templates/cryplant_sets.php) - where line 128 is "$content  .= $sm2->player($track, $options);"

In the module settings I have Default Single Player set to Page Player, no Bar-UI options, Cassette options to ma-r90, all Allowed Formats on.

I installed Tracy Debugger but this is far beyond my skills to operate....

Share this post


Link to post
Share on other sites

right - as i pointed out, the error is because the $sm2 variable is not the instance of the module.  player() on null means that $sm2 is null.

You said this in your init

$sm2 = $modules->get('TextformatterSoundmanager');

You either lost the variable between your init and the template, or you are in a different namespace;

whatever the case, you can easily solve it by just re-referencing the module right before the code; just repeat that code before the other code; none of the other items you mentioned would affect anything, field name,

Share this post


Link to post
Share on other sites

All '_init.php', header and 'cryplant_sets.php' have <?php namespace ProcessWire; on line 1. Running PW 3.0.98 - PHP 5.6.38.

	$sm2 = $modules->get('TextformatterSoundmanager');
	$options = [
		'type' => 'cassette',
		'cassette' => 'ma-r90',
	];
	$track = $page->audio->first();
	$content .= $sm2->player($track, $options);

Above code in the 'cryplant_sets.php' template gives no error but no cassette either.... 

Share this post


Link to post
Share on other sites

well you're probably not doing delayed output, so that code won't output anything; you'd need to echo if you are doing direct output, like

echo $sm2->player($track, $options);

Share this post


Link to post
Share on other sites

for some reason the 2nd one has the wrong class name, it looks like the classname is added 2x - this is what your api version classname looks like: ma-r90ma-r90 but it should only be ma-r90

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By teppo
      Needed a really simple solution to embed audio files within page content and couldn't find a module for that, so here we go. Textformatter Audio Embed works a bit like Textformatter Video Embed, converting this:
      <p>https://www.domain.tld/path/to/file.mp3</p> Into this:
      <audio controls class="TextformatterAudioEmbed"> <source src="https://www.domain.tld/path/to/file.mp3" type="audio/mpeg"> </audio> The audio element has pretty good browser support, so quite often this should be enough to get things rolling 🙂
      GitHub repository: https://github.com/teppokoivula/TextformatterAudioEmbed Modules directory: https://modules.processwire.com/modules/textformatter-audio-embed/
    • By Richard Jedlička
      Tense    
      Tense (Test ENvironment Setup & Execution) is a command-line tool to easily run tests agains multiple versions of ProcessWire CMF.
      Are you building a module, or a template and you need to make sure it works in all supported ProcessWire versions? Then Tense is exactly what you need. Write the tests in any testing framework, tell Tense which ProcessWire versions you are interested in and it will do the rest for you.

      See example or see usage in a real project.
      How to use?
      1. Install it: 
      composer global require uiii/tense 2. Create tense.yml config:
      tense init 3. Run it:
      tense run  
      For detailed instructions see Github page: https://github.com/uiii/tense
       
      This is made possible thanks to the great wireshell tool by @justb3a, @marcus and others.
       
      What do you think about it? Do you find it useful? Do you have some idea? Did you find some bug? Tell me you opinion. Write it here or in the issue tracker.
    • By Chris Bennett
      Hi all, I am going round and round in circles and would greatly appreciate if anyone can point me in the right direction.
      I am sure I am doing something dumb, or missing something I should know, but don't. Story of my life 😉

      Playing round with a module and my basic problem is I want to upload an image and also use InputfieldMarkup and other Inputfields.
      Going back and forth between trying an api generated page defining Fieldgroup, Template, Fields, Page and the InputfieldWrapper method.

      InputfieldWrapper method works great for all the markup stuff, but I just can't wrap my head around what I need to do to save the image to the database.
      Can generate a Field for it (thanks to the api investigations) but not sure what I need to do to link the Inputfield to that. Tried a lot of stuff from various threads, of varying dates without luck.
      Undoubtedly not helped by me not knowing enough.

      Defining Fieldgroup etc through the api seems nice and clean and works great for the images but I can't wrap my head around how/if I can add/append/hook the InputfieldWrapper/InputfieldMarkup stuff I'd like to include on that template as well. Not even sure if it should be where it is on ___install with the Fieldtype stuff or later on . Not getting Tracy errors, just nothing seems to happen.
      If anyone has any ideas or can point me in the right direction, that would be great because at the moment I am stumbling round in the dark.
       
      public function ___install() { parent::___install(); $page = $this->pages->get('name='.self::PAGE_NAME); if (!$page->id) { // Create fieldgroup, template, fields and page // Create new fieldgroup $fmFieldgroup = new Fieldgroup(); $fmFieldgroup->name = MODULE_NAME.'-fieldgroup'; $fmFieldgroup->add($this->fields->get('title')); // needed title field $fmFieldgroup->save(); // Create new template using the fieldgroup $fmTemplate = new Template(); $fmTemplate->name = MODULE_NAME; $fmTemplate->fieldgroup = $fmFieldgroup; $fmTemplate->noSettings = 1; $fmTemplate->noChildren = 1; $fmTemplate->allowNewPages = 0; $fmTemplate->tabContent = MODULE_NAME; $fmTemplate->noChangeTemplate = 1; $fmTemplate->setIcon(ICON); $fmTemplate->save(); // Favicon source $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeImage"); $fmField->name = 'fmFavicon'; $fmField->label = 'Favicon'; $fmField->focusMode = 'off'; $fmField->gridMode = 'grid'; $fmField->extensions = 'svg png'; $fmField->columnWidth = 50; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon(ICON); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($fmField); // Favicon Silhouette source $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeImage"); $fmField->name = 'fmFaviconSilhouette'; $fmField->label = 'SVG Silhouette'; $fmField->notes = 'When creating a silhouette/mask svg version for Safari Pinned Tabs and Windows Tiles, we recommend setting your viewbox for 0 0 16 16, as this is what Apple requires. In many cases, the easiest way to do this in something like illustrator is a sacrificial rectangle with no fill, and no stroke at 16 x 16. This forces the desired viewbox and can then be discarded easily using something as simple as notepad. Easy is good, especially when you get the result you want without a lot of hassle.'; $fmField->focusMode = 'off'; $fmField->extensions = 'svg'; $fmField->columnWidth = 50; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon(ICON); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($fmField); // Create: Open Settings Tab $tabOpener = new Field(); $tabOpener->type = new FieldtypeFieldsetTabOpen(); $tabOpener->name = 'fmTab1'; $tabOpener->label = "Favicon Settings"; $tabOpener->collapsed = Inputfield::collapsedNever; $tabOpener->addTag(MODULE_NAME); $tabOpener->save(); // Create: Close Settings Tab $tabCloser = new Field(); $tabCloser->type = new FieldtypeFieldsetClose; $tabCloser->name = 'fmTab1' . FieldtypeFieldsetTabOpen::fieldsetCloseIdentifier; $tabCloser->label = "Close open tab"; $tabCloser->addTag(MODULE_NAME); $tabCloser->save(); // Create: Opens wrapper for Favicon Folder Name $filesOpener = new Field(); $filesOpener->type = new FieldtypeFieldsetOpen(); $filesOpener->name = 'fmOpenFolderName'; $filesOpener->label = 'Wrap Folder Name'; $filesOpener->class = 'inline'; $filesOpener->collapsed = Inputfield::collapsedNever; $filesOpener->addTag(MODULE_NAME); $filesOpener->save(); // Create: Close wrapper for Favicon Folder Name $filesCloser = new Field(); $filesCloser->type = new FieldtypeFieldsetClose(); $filesCloser->name = 'fmOpenFolderName' . FieldtypeFieldsetOpen::fieldsetCloseIdentifier; $filesCloser->label = "Close open fieldset"; $filesCloser->addTag(MODULE_NAME); $filesCloser->save(); // Create Favicon Folder Name $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeText"); $fmField->name = 'folderName'; $fmField->label = 'Favicon Folder:'; $fmField->description = $this->config->urls->files; $fmField->placeholder = 'Destination Folder for your generated favicons, webmanifest and browserconfig'; $fmField->columnWidth = 100; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon('folder'); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($tabOpener); $fmFieldgroup->add($filesOpener); $fmFieldgroup->add($fmField); $fmFieldgroup->add($filesCloser); $fmFieldgroup->add($tabCloser); $fmFieldgroup->save(); /////////////////////////////////////////////////////////////// // Experimental Markup Tests $wrapperFaviconMagic = new InputfieldWrapper(); $wrapperFaviconMagic->attr('id','faviconMagicWrapper'); $wrapperFaviconMagic->attr('title',$this->_('Favicon Magic')); // field show info what $field = $this->modules->get('InputfieldMarkup'); $field->name = 'use'; $field->label = __('How do I use it?'); $field->collapsed = Inputfield::collapsedNever; $field->icon('info'); $field->attr('value', 'Does this even begin to vaguely work?'); $field->columnWidth = 50; $wrapperFaviconMagic->add($field); $fmTemplate->fields->add($wrapperFaviconMagic); $fmTemplate->fields->save(); ///////////////////////////////////////////////////////////// // Create page $page = $this->wire( new Page() ); $page->template = MODULE_NAME; $page->parent = $this->wire('pages')->get('/'); $page->addStatus(Page::statusHidden); $page->title = 'Favicons'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } }  
    • By Sebi
      Since it's featured in ProcessWire Weekly #310, now is the time to make it official:
      Here is Twack!
      I really like the following introduction from ProcessWire Weekly, so I hope it is ok if I use it here, too. Look at the project's README for more details!
      Twack is a new — or rather newish — third party module for ProcessWire that provides support for reusable components in an Angular-inspired way. Twack is implemented as an installable module, and a collection of helper and base classes. Key concepts introduced by this module are:
      Components, which have separate views and controllers. Views are simple PHP files that handle the output for the component, whereas controllers extend the TwackComponent base class and provide additional data handling capabilities. Services, which are singletons that provide a shared service where components can request data. The README for Twack uses a NewsService, which returns data related to news items, as an example of a service. Twack components are designed for reusability and encapsulating a set of features for easy maintainability, can handle hierarchical or recursive use (child components), and are simple to integrate with an existing site — even when said site wasn't originally developed with Twack.
      A very basic Twack component view could look something like this:
      <?php namespace ProcessWire; ?> <h1>Hello World!</h1> And here's how you could render it via the API:
      <?php namespace Processwire; $twack = $modules->get('Twack'); $hello = $twack->getNewComponent('HelloWorld'); ?> <html> <head> <title>Hello World</title> </head> <body> <?= $hello->render() ?> </body> </html> Now, just to add a bit more context, here's a simple component controller:
      <?php namespace ProcessWire; class HelloWorld extends TwackComponent { public function __construct($args) { parent::__construct($args); $this->title = 'Hello World!'; if(isset($args['title'])) { $this->title = $args['title']; } } } As you can see, there's not a whole lot new stuff to learn here if you'd like to give Twack a try in one of your projects. The Twack README provides a really informative and easy to follow introduction to all the key concepts (as well as some additional examples) so be sure to check that out before getting started. 
      Twack is in development for several years and I use it for every new project I build. Also integrated is an easy to handle workflow to make outputs as JSON, so it can be used to build responses for a REST-api as well. I will work that out in one section in the readme as well. 
      If you want to see the module in an actual project, I have published the code of www.musical-fabrik.de in a repository. It runs completely with Twack and has an app-endpoint with ajax-output as well.
      I really look forward to hear, what you think of Twack🥳!
      Features Installation Usage Quickstart: Creating a component Naming conventions & component variants Component Parameters directory page parameters viewname Asset handling Services Named components Global components Ajax-Output Configuration Versioning License Changelog
    • By Robin S
      Page Reference Default Value
      Most ProcessWire core inputfield types that can be used with a Page Reference field support a "Default value" setting. This module extends support for default values to the following core inputfield types:
      Page List Select Page List Select Multiple Page Autocomplete (single and multiple) Seeing as these inputfield types only support the selection of pages a Page List Select / Page List Select Multiple is used for defining the default value instead of the Text / Textarea field used by the core for other inputfield types. This makes defining a default value a bit more user-friendly.
      Note that as per the core "Default value" setting, the Page Reference field must be set to "required" in order for the default value to be used.
      Screenshot

       
      https://github.com/Toutouwai/PageReferenceDefaultValue
      https://modules.processwire.com/modules/page-reference-default-value/
×
×
  • Create New...