IpRanges.php in IP Ranges 8
File
lib/Drupal/ip_ranges/Entity/IpRanges.php
View source
<?php
namespace Drupal\ip_ranges\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldDefinition;
class IpRanges extends ContentEntityBase implements ContentEntityInterface {
public function getType() {
return $this
->get('type')->value;
}
public function getIpLower() {
return $this
->get('ip_lower')->value;
}
public function getIpHigher() {
return $this
->get('ip_higher')->value;
}
public function getIpDisplay() {
if ($this
->getIpLower() != $this
->getIpHigher()) {
$ip_list = long2ip($this
->getIpLower()) . '-' . long2ip($this
->getIpHigher());
}
else {
$ip_list = long2ip($this
->getIpLower());
}
return $ip_list;
}
public function getDescription() {
return $this
->get('description')->value;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['bid'] = FieldDefinition::create('integer')
->setLabel(t('User Restrictions ID'))
->setDescription(t('The User Restrictions ID.'))
->setReadOnly(TRUE);
$fields['uuid'] = FieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The User Restrictions UUID.'))
->setReadOnly(TRUE);
$fields['ip_lower'] = FieldDefinition::create('string')
->setLabel(t('IP'))
->setDescription(t('Text mask used for filtering restrictions.
%: Matches any number of characters, even zero characters.
_: Matches exactly one character.'))
->setRequired(TRUE)
->setSettings(array(
'default_value' => '',
'max_length' => 15,
));
$fields['ip_higher'] = FieldDefinition::create('string')
->setLabel(t('IP'))
->setDescription(t('Text mask used for filtering restrictions.
%: Matches any number of characters, even zero characters.
_: Matches exactly one character.'))
->setSettings(array(
'default_value' => '',
'max_length' => 15,
));
$fields['type'] = FieldDefinition::create('boolean')
->setLabel(t('Restriction status'))
->setDescription(t('A boolean indicating whether the ip range is whitelisted or blacklisted.'))
->setSetting('default_value', 1)
->setDisplayConfigurable('form', TRUE);
$fields['description'] = FieldDefinition::create('string')
->setLabel(t('Range desctiption'))
->setDescription(t('Optional description for the IP Range.'))
->setSettings(array(
'default_value' => '',
'max_length' => 254,
));
return $fields;
}
}
Classes
Name |
Description |
IpRanges |
Defines a Block configuration entity class. |