Jump to content
Esther E.

IC5: UI Extensions, Part I

Only a little over a week into our development tools announcements, and there is already lots of buzz about our new UI Extensions. The UI Extensions handle a variety of functionality, and we will discuss them all in detail, over the course of multiple blog entries. For today, we'll start with an introduction and an overview of some of the basic usage.

 

Features and Functionality

UI Extensions are extensions to a single content class - Nodes, Items, Comments, or Reviews. With a UI Extension, you can:

  • Add custom CSS classes and data attributes
  • Add options to content menus
  • Add badges to content item headers
  • Add fields to content forms
  • ACP-related functionality (for nodes)

And a couple of other small things that we'll cover here.

Could contain: Computer, Electronics, Tablet Computer, Page, Text

Setup

The Application Developer Center has 4 new options in the Extensions tab:

  • UIComment
  • UIItem
  • UINode
  • UIReview

To add a UI extension, simply create a class under the appropriate extension type.

Note: We are working on improving this process, however, those changes will likely be introduced at a later date.

The default extension file will be generated in the appropriate directory within your application's extensions folder. All UI Extensions are abstracted, so if you omit a method from your class, or if new methods are introduced later on, your extension will not throw an error.

All UI Extension methods receive the object as the first parameter.

 

UI Extensions for... UI

The idea for UI Extensions was born when we were reviewing the most common third-party development hooks. With the removal of theme hooks, we needed a way for developers to add custom CSS and attributes to areas such as topic rows, the author panel, among others. Even with the theme hooks in v4, the way to accomplish this was less than ideal. Adding a CSS class typically required at least 2 hooks per template - one to determine the correct class (usually based on custom logic) and one to insert the class as a variable. It was tedious and finicky at best.

All UI Extensions include the following methods:

  • css
    Returns an array of CSS classes that will be applied to the object
  • dataAttributes
    Returns an array of data attributes (as "key=value", "key=value") that will be applied to the object

To insert those values into the appropriate location, our templates now contain the following syntax:

{$object->ui( 'css' )}

and

{$object->ui( 'dataAttributes' )}

Let's examine the Content::ui() method (identical to Model::ui().)

public function ui( string $method, ?array $payload=array(), bool $returnAsArray=false, string $separator = " " ) : array|string

The ui method accepts 4 arguments: the method name, an optional payload (determined based on the method being called), the option to return as an array (vs a string), and an optional separator (when data is returned as a string). The defaults for this method were set for the simplest, shortest syntax within the templates, as seen above. You may also see syntax like this:

foreach( $this->ui( 'menuItems', array(), TRUE ) as $key => $link )
{
	$links[$key] = $link;
}

As you can see, in this case the ui method will return the results as an array.

 

Class-Specific Methods

Some of our extensions include methods that are applicable only to objects of that type.

  • UIItem::sidebar()
    Returns HTML that will be included in the contextual sidebar when viewing the item
  • UIComment::authorPanel()
    Returns HTML to be inserted into the author panel of a post

Note: All methods in the UIComment extension are also available in UIReview.

 

We hope this entry gave you a glimpse into what will be available with this new tool, and a better understanding of the direction we are taking with our toolkit. We will discuss the other features of this tool in upcoming blog entries.

Comments

Recommended Comments

  • Management
12 minutes ago, Adriano Faria said:

Hello,

Is this part specific for content? I suppose we will be able to do this in other places too and not only in content related stuff, right? There are tons of templates and forms out there that we can extend today.

What other forms do you want extended? We did discuss internally the registration form where custom profile fields aren't powerful enough (in that there requires some PHP/SQL processing of input data).

Link to comment
Share on other sites

A few examples: 

https://invisioncommunity.com/files/file/7833-profile-field-per-user-group/

https://invisioncommunity.com/files/file/8783-enhanced-links-moderation/

There are a ton from other devs. Everywhere. For the most varied reasons and purposes.

Anyway, this is just to confirm that this will not be the game-changer; it was expected and I really don’t want to enter in another debate like the first blog entry. That’s all I have to say. 👍

Link to comment
Share on other sites

Quote

UI Extensions are extensions to a single content class - Nodes, Items, Comments, or Reviews. With a UI Extension, you can:

  • Add custom CSS classes and data attributes
  • Add options to content menus
  • Add badges to content item headers
  • Add fields to content forms
  • ACP-related functionality (for nodes)

Only add? What about modify/replace/adjust/update/remove?

To be clear, we can't do anything from this list, right? I mean that list:

Could contain: Page, Text

Link to comment
Share on other sites

5 minutes ago, DawPi said:

Only add? What about modify/replace/adjust/update/remove?

To be clear, we can't do anything from this list, right? I mean that list:

Could contain: Page, Text

You still have full control if you're building a custom app. If you're creating something new, you still can overload the base class methods and arrange things any way you want. It's just the IPS classes that can no longer be manipulated.

Link to comment
Share on other sites

3 minutes ago, Adriano Faria said:

I have a few resources but also know others who restrict items viewing by extending \IPS\Helpers\Table\Content::getRows().

Will this be possible somehow?

Can you elaborate please? 

Link to comment
Share on other sites

Basically, I have a content item that has a "privacy" column. If it is private, it shows to the item creator only; public shows to everyone. I can't use my getItemsWithPermission() because, you know, it is static so I can't check the author against the logged member. Even if I could use it, I wouldn't use it because the item must be accessible by direct link. It just can't be listed.

Edited by Adriano Faria
Link to comment
Share on other sites

20 minutes ago, Adriano Faria said:

Basically, I have a content item that has a "privacy" column. If it is private, it shows to the item creator only; public shows to everyone. I can't use my getItemsWithPermission() because, you know, it is static so I can't check the author against the logged member. Even if I could use it, I wouldn't use it because the item must be accessible by direct link. It just can't be listed.

I've added your request to our internal list for discussion.

Link to comment
Share on other sites

On 8/2/2023 at 12:14 PM, Matt said:

That is correct, you can add, but you cannot remove or modify existing data.

We do have a limited template front-end hook system (yet to be blogged) but that again does not have a replace option.

 

On 8/2/2023 at 12:20 PM, Daniel F said:


That said, you can also use always JS and CSS to manipulate the output.

I'm curious, if you can achieve it via a hack and you know people will need to do it, why not simply retain the ability to modify or replace? At least then it would be more controlled. 🤔

Edited by The Old Man
Link to comment
Share on other sites

2 minutes ago, The Old Man said:

I'm curious, if you can achieve it via a hack and you know people will need to do it, why not simply retain the ability to modify or replace? At least then it would be more controlled. 🤔

Actually, it would be less controlled and not as easily broken

Link to comment
Share on other sites

22 hours ago, The Old Man said:

 

I'm curious, if you can achieve it via a hack and you know people will need to do it, why not simply retain the ability to modify or replace? At least then it would be more controlled. 🤔

The thing is that we don't really think people will need it. Or at least, the majority of people won't need it. You'll always have some outside use case, and in those instances, Daniel's suggestion is correct. 

Link to comment
Share on other sites

On 8/2/2023 at 6:14 AM, Matt said:

That is correct, you can add, but you cannot remove or modify existing data.

We do have a limited template front-end hook system (yet to be blogged) but that again does not have a replace option.

Excellent 
This prevents conflicts between 3rd-party apps. Currently, if there is an app that removes or replaces attributes and another app wants to work by using these attributes, it is not possible. I had encountered this problem.

Link to comment
Share on other sites


×
×
  • Create New...